使用快速量值,輕鬆執行常用及功能強大的計算 (預覽)Use Quick measures to easily perform common and powerful calculations (Preview)

Power BI Desktop 的 2017 年 4 月版本開始,您可以使用快速量值,快速又輕鬆地執行常用、功能強大的計算。Starting with the April 2017 release of Power BI Desktop, you can use Quick measures to quickly and easily perform common, powerful calculations. 快速量值會依據您在對話方塊中提供的輸入,在幕後執行一組 DAX 命令 (DAX 是現成的,所以您不必撰寫),然後顯示結果,供您在報表中使用。A Quick measure runs a set of DAX commands behind the scenes (you don’t have to write the DAX – it’s done for you) based input you provide in a dialog box, then presents the results for you to use in your report. 更棒的是,您可以查看快速量值所執行的 DAX,以啟發或拓展您的 DAX 知識。Best of all, you can see the DAX that’s executed by the Quick measure, and jump-start or expand your own DAX knowledge.

以右鍵按一下 [欄位] 區中的欄位,然後從出現的功能表中選取 [快速量值],即可建立快速量值You create Quick measures by right-clicking a field in the Fields well, then selecting Quick measures from the menu that appears. 您也可以用右鍵按一下現有視覺效果的 [值] 窗格的任何值 (例如「橫條圖」視覺效果中的 [值] 欄位)。You can also right-click any value in the Values pane of an existing visual (such as the Values field in a Bar chart visual). 計算有多種可用的分類,也有多種方式可以修改各項計算,以符合您的需求。There are many available categories of calculations, and ways to modify each calculation to fit your needs.

啟用快速量值預覽Enable the Quick measures preview

2017 年 4 月發行的 Power BI Desktop 開始,您可以試用新的 [快速量值]。You can try the new Quick measures feature beginning with the April 2017 release of Power BI Desktop. 若要啟用這項預覽功能,請選取 [檔案] > [選項及設定] > [選項] > [預覽功能],然後選取 [快速量值] 旁的核取方塊。To enable this preview feature, select File > Options and Settings > Options > Preview Features, then select the checkbox beside Quick measures. 您完成選取後必須重新啟動 Power BI Desktop。You'll need to restart Power BI Desktop after you make the selection.

完成選取後,必須重新啟動 Power BI DesktopYou'll need to restart Power BI Desktop after you make the selection.

使用快速量值Using Quick measures

若要建立 [快速量值],請在 Power BI Desktop 中以右鍵按一下 [欄位] 區中的欄位 (任一欄位),然後從出現的功能表中選取 [快速量值]。To create a Quick measure, right-click on a field (any field) in the Fields well in Power BI Desktop and select Quick measure from the menu that appears.

目前載入的資料集必須可進行模型化,才能使用 [快速量值]。Modeling must be available on the dataset currently loaded in order for Quick measures to be available. 否則,當您以滑鼠右鍵按一下 [欄位] 清單時,即時連線 (例如 Power BI 服務資料集的連線) 不會顯示 [快速量值] 功能表項目 (SSAS 即時連線則除外)。As such, live connections (such as a connection to a Power BI service dataset) will not display the Quick measures menu item when the Fields list is right-clicked, with the exception of SSAS live connections.

使用 SQL Server Analysis Services (SSAS) 即時連線時,可以使用部分快速量值When using SQL Server Analysis Services (SSAS) live connections, some Quick measures are available. Power BI Desktop 只會顯示建立連線之 SSAS 版本支援的快速量值集合。Power BI Desktop displays only the collection of Quick measures that are supported for the version of SSAS to which the connection is made. 因此,如果您連線到 SSAS 即時資料來源且看不到清單中的某些快速量值,這是因為您所連線的 SSAS 版本不支援 用來實作該快速量值的 DAX 量值。So if you are connected to a SSAS live data source, and you do not see certain Quick measures in the list, it's because the SSAS version to which you are connected does not support the DAX measure used to implement that Quick measure.

從右鍵功能表選取時,以下 [快速量值] 視窗隨即顯示,讓您可以選取想要的計算,以及您要執行計算的目標欄位。When selected from the right-click menu, the following Quick measures window appears, allowing you to select the calculation you want, and the fields against which you want to calculation to be run.

當您選取下拉式功能表時,系統會顯示可用的 [快速量值] 長清單。When you select the drop-down menu, you're presented with the long list of available Quick measures.

快速量值計算類型有五種不同群組,各自有一組計算。There are five distinct groups of Quick measure calculation types, each with a collection of calculations. 群組和計算如下:Those groups and calculations are the following:

  • 分類中的彙總Aggregate within a category
    • 分類中的平均Average within category
    • 分類中的差異Variance within category
    • 分類中的最大值Max within category
    • 分類中的最小值Min within category
    • 每個分類的加權平均Weighted average per category
  • 篩選和基準Filters and baselines
    • 篩選的量值Filtered measure
    • 基準差異Difference from baseline
    • 基準差異百分比Percentage difference from baseline
    • 新類別的總計Totals from new categories
  • 時間智慧Time intelligence
    • 年初迄今總計Year-to-date total
    • 季初迄今總計Quarter-to-date total
    • 月初迄今總計Month-to-date total
    • 年度變化Year over year change
    • 季度變化Quarter over quarter change
    • 月度變化Month-over-month change
    • 移動平均Rolling average
  • 總計Totals
    • 累積總計Running total
    • 分類總計 (套用篩選)Total for category (filters applied)
    • 分類總計 (未套用篩選)Total for category (filters not applied)
  • 數學運算Mathematical operations
    • 新增Addition
    • Subtraction
    • Multiplication
    • Division
    • 差異百分比Percentage difference
  • 文字Text
    • 星級評等Star rating
    • 值的串連清單Concatenated list of values

我們很期待擴增這些計算,也想要知道您想要哪些快速量值,以及您是否對快速量值有任何想法 (包括基礎 DAX 公式) 要提交給我們參考。We anticipate adding to these calculations, and want to hear from you about which Quick measures you'd like to see, and if you have ideas (including underlying DAX formulas) for Quick measures that you'd like to submit for consideration. 您可以在文末找到相關的詳細資訊。More on that at the end of this article.

快速量值的範例Example of Quick measures

讓我們看看其中一個快速量值實際執行的範例。Let's take a look at an example of these Quick measures in action.

下列矩陣視覺效果顯示不同電子產品的銷售資料表。The following Matrix visual shows a table of sales for various electronics products. 這是包含各分類總計的基本資料表。It's a basic table that includes the total for each category.

當我們以右鍵按一下 [值] 欄位並選取 [快速量值],可以選取 [分類中的平均] 作為「計算」,然後選取 [Sum of SalesAmount] 作為「基底值」,再從右側窗格的 [欄位] 方塊將該欄位拖曳到左側 [分類] 區段中,以指定 SalesAmountWhen we right-click the Values field well and select Quick measures, we can select Average within category as the Calculation, then select Sum of SalesAmount as the Base value, then specify SalesAmount by dragging that field from the Fields box on the right pane, into the Category section on the left.

當我們選取 [確定] 時,會看到一些有趣的事情發生,如本清單後的圖片所示:When we select OK, we see a few interesting things occur, as shown in the image following this list:

  1. 矩陣視覺效果現在有一個新的資料行,顯示我們的計算 (在這個案例中是「SalesAmount 中的平均 SalesAmount」)。The Matrix visual now has a new column that shows our calculation (in this case, Average SalesAmount within SalesAmount).
  2. 量值已經建立並在 [欄位] 區中提供使用,而且有醒目提示 (Power BI 會在周圍加上黃色方塊)。A new measure has been created and is available in the Fields well, and it's highlighted (Power BI puts a yellow box is around it). 不僅其原先建立的視覺效果,報表中其他任何視覺效果也都可以使用這個量值。This measure is available to any other visual in the report, not just the visual for which it was originally created.
  3. 快速量值建立的 DAX 公式會顯示在 [公式] 列中。The DAX formula that was created for the Quick measure is displayed in the Formula bar.

若要開始使用第一個項目,請注意快速量值已套用到視覺效果。To start with the first item, notice that the Quick measure was applied to the visual. 現在有新的資料行及相關聯的值,兩者都以建立的快速量值為基礎。There's a new column and associated value, both of which are based on the Quick measure that was created.

其次,快速量值會顯示在資料模型的 [欄位] 區中,而且可以在其他任何視覺效果使用,方式如同模型中的其他任何模型。Second, the Quick measure shows up in the Fields well of the data model, and can be used like any other field in the model, for any other visual. 在下圖中,我們使用快速量值所建立的新欄位,建立了簡易的橫條圖視覺效果。In the following image, a quick bar chart visual was created by using the new field created by the Quick measure.

讓我們前往下一章,討論第三部份:DAX 公式。Let's head to the next section to discuss that third item, DAX formulas.

了解使用快速量值的 DAXLearn DAX using Quick measures

快速量值功能另一個很大的優勢是,您可以直接從中看到建立來實作量值的 DAX 公式。Another great advantage of the Quick measures feature is that it directly shows you the DAX formula that was created to implement the measure. 在下圖中,我們選取了快速量值所建立的量值 (現在已經在 [欄位] 區中,所以只要按一下即可)。In the following image, we've selected the measure that was created by the Quick measure (it's now in the Fields well, so we just have to click it). 這樣做之後,[公式列] 隨即出現,顯示 Power BI 建立來實作量值的 DAX 公式。When we do so, the Formula bar appears, showing the DAX formula that Power BI created to implement the measure.

這項功能本身很棒,因為您可以看到量值背後的公式。This is nice by itself, since it shows you the formula behind the measure. 但更重要的是,還能讓您使用快速量值了解如何建立基礎 DAX 公式。But more importantly, perhaps, it lets you use Quick measures to see how the underlying DAX formulas should be created.

想像您需要進行年度計算,但不確定如何建立 DAX 公式 (或您不知道從哪裡著手!)。Imagine you need to do a year-over-year calculation, but you're not quite sure how to structure the DAX formula (or, you have no idea where to start!). 與其在桌前懊惱,不如使用年度變化計算來建立快速量值,並查看執行方式。Instead of banging your head on the desk, you could create a Quick measure using the Year over year change calculation, and see what happens. 也就是建立快速量值並查看其如何在視覺效果中顯示、查看 DAX 公式如何運作,然後直接對 DAX 進行變更或建立另一個量值,直到計算滿足您的需求或預期為止。As in, create the Quick measure and see how it appears in your visual, see how the DAX formula worked, then make changes either directly to the DAX, or create another measure, until the calculations meet your needs or expectations.

這就像是有一位敏捷的老師,只要您按幾下就能立即回應您的假設問題。It's like having a quick teacher that immediately responds to your what-if questions by a few clicks. 如果不想要這些量值,您可以隨時從模型中予以刪除,方式相當簡單,只要以右鍵按一下量值後選取 [刪除] 即可。You can always delete those measures from your model if you don't like them - that's as easy as right-clicking the measure and selecting delete.

在您的量值呈現完美狀態後,您可以使用相同的右鍵功能表,按照自己的想法為其重新命名。And once you do have the measure perfected, you can rename it however you'd like, using the same right-click menu.

限制與考量Limitations and considerations

在這份預覽版的 [快速預覽] 中,有幾點限制和考量要留意。In this preview release of the Quick measures, there are a few limitations and considerations to keep in mind.

  • 快速量值僅在您可以修改模型時可供使用,當您使用 DirectQuery 或大多數即時連線時則無法使用 (如上所述支援 SSAS 即時連線)。Quick measures are only available if you can modify the model, which isn't the case when you're working with DirectQuery or most Live connections (SSAS live connections are supported, as previously explained).
  • 新增到 [欄位] 區的量值可以搭配報表中任何視覺效果使用。The measure that's added to the Fields well can be used with any visual in the report.
  • 您可以隨時查看與快速量值相關的 DAX,方法是選取 [欄位] 區中已建立的量值,然後查看 [公式列] 中的公式。You can always see the DAX associated with a Quick measure by selecting the created measure in the Fields well, then looking at the formula in the Formula bar.

警告

快速量值目前「只會」產生 DAX 陳述式,並以逗號作為引數分隔符號。Quick measures currently only generate DAX statements with commas for argument separators. 如果 Power BI Desktop 版本的當地語系化語言是以逗號作為小數分隔符號,快速量值就無法正常運作。If your version of Power BI Desktop is localized to a language that uses commas as decimal separators, quick measures will not operate properly.

時間智慧與快速量值Time intelligence and Quick measures

從 2017 年 10 月更新的 Power BI Desktop 開始,您可以使用自己的自訂日期資料表並搭配時間智慧快速量值Beginning with the October 2017 update to Power BI Desktop, you can use your own custom date tables with time intelligence Quick measures. 如果您的資料模型具有自訂日期資料表,您可以針對時間智慧快速量值使用該資料表中的主要日期資料行。If your data model has a custom date table, you can use the primary date column in that table for time intelligence quick measures. 您「必須」確定建立模型時,該資料表中的主要日期資料行已標示為「日期」資料表,如這篇文章中所述。You must ensure that when the model was built, that primary date column in that table was marked as a Date table, as described in this article.

其他資訊及範例Additional information and examples

我們預期會為各個快速量值計算提供範例和指引,因此請儘速回來查看焦點文章的更新。We anticipate providing examples and guidance for each of the Quick measures calculations, so please check back soon for updates on that focused article.

由於這是預覽功能,我們殷切期盼您的意見反應及想法。Since this is a Preview feature, we're especially interested in your feedback and your ideas.

對於尚未提供的快速量值有任何想法嗎?Have an idea for a Quick measure that isn't already provided? 太棒了!Great! 請查看這個頁面,並為您想在 Power BI Desktop 中看到的快速量值提交想法 (或 DAX 公式),我們會考慮在未來版本中,將其新增到提供的快速量值清單。Check out this page and submit your ideas (and DAX formula) for the Quick measure you'd like to see in Power BI Desktop, and we'll consider adding it to the provided list of Quick measures in a future release.