Measure performance by using KPIs, gauges, and cards

Một phần của tài liệu Analyzing and visualizing data by using microsoft power BI (Trang 123 - 130)

MORE INFO ALL MICROSOFT CERTIFICATIONS

Skill 2.3: Measure performance by using KPIs, gauges, and cards

Organizations usually have targets towards which they work. These targets, when compared to the actual figures, are often called Key Performance Indicators, or KPIs. KPIs help organizations with tracking how close they are to achieving their targets, as well as which areas fare better compared to others. In Power BI, there are several ways to visualize targets and actual figures. For example, you can display a value by itself in a Card visual, or you can use the KPI or Gauge visuals to compare actual and target figures.

If you want to follow the examples in this section, you can open the CH02-2.3Start.pbix file from the companion files folder.

This section covers how to:

Calculate the actual Calculate the target Calculate actual to target Configure values for gauges

Use the format settings to manually set values Calculate the actual

In general, every KPI has at least two parts: the base, or actual figure, and the target figure. In the data model that we have created so far, we already have the necessary data to calculate the actual. In the Sale table, there is the Total Excluding Tax column, from which you can create an explicit measure:

Total Actual Amount = SUM ( Sale[Total Excluding Tax] )

You can now use this measure in a Card visual. To do this, click on the Card visual icon in the Visualizations pane and then click on the check box next to the Total Actual Amount measure. Alternatively, drag the measure into the Fields field well below the visualizations icons. Another way to create a visual is to drag a measure onto the canvas or click the check box next to it, which will create a clustered column chart. You can then convert this visual into a Card visual by clicking on its icon in the Visualizations pane. Whatever method you choose, your visual should look as shown in Figure 2.53.

FIGURE 2.53 Card visual

With the card visual, you can use only one field. If you want to display several actuals in one visual, one way to do so would be a Multi-row Card. For instance, if you create a Multi-row card with Total Actual Amount, Total Profit, Total Target Amount, and Total Target Quantity as fields, your visual will look like in Figure 2.54.

Figure 2.54 Multi-row card

If instead, you want to use the KPI or Gauge visual, you need to calculate the target amount.

Calculate the target

Target figures are often provided in separate tables from actual figures, and they are usually at different granularity level. For example, businesses rarely set targets at day level; instead, they might set targets at monthly or yearly level. In our data model, we have target figures set at Calendar Year and Bill To Customer level. The problem with the measures we have now is that they will still show values when analyzed at other levels of granularity. For example, if we display the Total Target Amount measure by Calendar Year Label and Month like in Figure 2.55, we will see the same values for each month within a given Calendar Year Label.

FIGURE 2.55 Total Target Amount by Calendar Year Label and Month

These figures, while technically correct, are misleading to anyone looking at the report. This situation can be addressed in a few ways. First, the monthly figures can be divided by 12 so that they make sense at month level. However, if you browse the Date table at the day level, for instance, then you will again have to deal with this issue.

MORE INFO ALLOCATING TARGETS AT DIFFERENT GRANULARITIES

If you want to allocate your target or budget figures at higher granularity levels—for example, at month or day level when you only have yearly figures—you can use the budget pattern developed by Alberto Ferrari and Marco Russo. For more details and examples, see

“Budget Patterns” at http://www.daxpatterns.com/budget-patterns/.

Second, these values can be hidden using DAX so that you only see the figures at Calendar Year level. You also need to take into account the columns from the Customer table that are at higher level of granularity than the Target figures, as well as all other tables.

By using the ISFILTERED function, you can check whether a column has been filtered explicitly. To see the effect of the function, create the following measure and slice it by Calendar Year Label. The resulting table are shown in Figure 2.56.

CYL Filtered = ISFILTERED ( 'Date'[Calendar Year Label] )

FIGURE 2.56 The CYL Filtered measure sliced by Calendar Year Label

Note how the measure shows False at the total level and True everywhere else. This is because at the total level, Calendar Year Label is not filtered. If you have a slicer that selects a few Calendar Year Label values, the total level will also display True. However, if filtered by Month, for instance, the total would still show False. In this case, you can use the ISCROSSFILTERED function that checks whether the table in which the column exists has any other filters applied. You can now create the following measure, add it to the table from Figure 2.56 and slice it by Month.

CYL CrossFiltered = ISCROSSFILTERED ( 'Date'[Calendar Year Label] ) The results are shown in Figure 2.57.

FIGURE 2.57 CYL CrossFiltered in a matrix visual

Note how when we slice by Month, the CYL Filtered measure still shows False at the total level, yet the CYL CrossFiltered measure shows True.

This is because there is a filter on the Date table which cross-filters Calendar Year Label, even if we do not see a difference in this case.

MORE INFO ISFILTERED AND ISCROSSFILTERED

For more information on these two functions, refer to “ISFILTERED Function (DAX)” at https://msdn.microsoft.com/en-

us/library/gg492163.aspx, and “ISCROSSFILTERED Function (DAX)” at https://msdn.microsoft.com/en-us/library/gg492197.aspx.

You can now create a measure that checks if the currently browsed granularity is supported by the Target table:

Click here to view code image Target Is Valid = NOT (

-- Check the Date table granularity ISFILTERED ( 'Date'[Calendar Month Label] ) || ISFILTERED ( 'Date'[Date] ) || ISFILTERED ( 'Date'[Day] )

|| ISFILTERED ( 'Date'[Fiscal Month Label] ) || ISFILTERED ( 'Date'[Fiscal Year Label] ) || ISFILTERED ( 'Date'[Month] )

|| ISFILTERED ( 'Date'[Short Month] ) -- Check the Customer table granularity || ISFILTERED ( Customer[Customer] ) || ISFILTERED ( Customer[Postal Code] ) || ISFILTERED ( Customer[Primary Contact] ) -- Check other tables

|| ISCROSSFILTERED ( City ) || ISCROSSFILTERED ( Employee ) || ISCROSSFILTERED ( 'Stock Item' ) )

NOTE COMMENTS IN DAX

You can write both single- and multi-line comments in DAX. For single-line comments, you need to prefix your code with a double forward slash (//) or a double dash (--), like in the Target table formula above. For multi-line comments, you need to write them between /* and */.

Note how ISCROSSFILTERED can also accept a table as a parameter, simplifying checking whether a filter has been applied on any of its columns. At this stage, create the following measure and put it into the table from Figure 2.55.

Click here to view code image

Target Amount = IF ( [Target Is Valid], [Total Target Amount] ) A sample of results can be seen in Figure 2.58.

Figure 2.58 The Target Amount measure used in a table

At this stage, to compare the actual and target figures, use the KPI visual, which has three field wells:

Indicator (actual or base value) Trend axis

Target goals (one or two)

Only the first two fields are required. If you use Total Actual Amount as the indicator and Calendar Year Label as Trend axis, you will see a visual like the one shown in Figure 2.59.

FIGURE 2.59 KPI visual with indicator and trend axis

The visual displays the indicator value that corresponds to the last point on the trend axis. In our case, it shows Total Actual Amount for CY2016. Behind the indicator value, its trend line with shaded underlying area is displayed.

At this point, add one or two target values to the Target Goals field well. If you add Target Amount, the KPI visual will look like the one in Figure 2.60.

Figure 2.60 KPI visual with target goal

Note how below the indicator, you see the target goal value for the last trend axis point, as well as the percentage difference between the indicator and target goal.

When you use a target goal field in a KPI visual, you can take advantage of conditional formatting. The indicator itself and background will be colored, and an icon will be displayed to the right of the indicator. By default, if the indicator is below the target value, the former will be colored red along with the background; the icon displayed will be the exclamation sign. If the indicator is above the target goal, the color will be green, and a tick mark will be displayed to the right of the indicator.

You can also use two target goals in a KPI visual. In this case, if the indicator is below both targets, the color will be red; if it is above both targets, the color will be green. If the indicator happens to be between the target goals, the color will be yellow, and a filled point will be displayed next to the indicator.

If for a certain KPI, the low indicator is good, you can change the conditional formatting behavior in the Direction drop-down list in the Color Coding section of the Format pane. The default behavior is called “High is good.” If you select “Low is good” as the direction, the background will be green if the indicator is below the target goal, and a tick mark will be displayed instead of the exclamation sign.

The Format pane has a brush icon and is next to the Fields pane; you can see it highlighted in Figure 2.61.

Figure 2.61 Format pane

In the Format pane, you can also turn on and off the goal value, distance, and trend axis. Also, you can adjust the default colors.

MORE INFO KPI VISUALS

For more details and a video tutorial on the KPI visuals, see “KPI visuals (Tutorial)” at https://docs.microsoft.com/en-us/power-bi/power-bi- visualization-kpi.

Calculate actual to target

There are several ways in which you can calculate the actual to target, or variance, figure. To calculate the absolute amount, you can create a measure that references both the actual and target measures and subtracts one from another:

Click here to view code image

Actual to Target = [Total Actual Amount] - [Target Amount]

To calculate the percentage difference, you can either reference the Actual to Target measure, or you can calculate it in one measure only. The following two expressions provide equivalent results:

Click here to view code image

Actual to Target % = DIVIDE ( [Actual to Target], [Target Amount] )

Actual to Target % = DIVIDE ( [Total Actual Amount] - [Target Amount], [Target Amount] )

The use of DIVIDE is important in this case because it handles division by zero, and the Target amount may be blank in case a user is browsing the model at the granularity level that Target Amount does not support. When Target Amount is (Blank), DIVIDE returns (Blank) as well. If we opted for the division operator instead, you would see “Infinity” in cases when Target Amount was (Blank).

Configure values for gauges The Gauge visual has five field wells:

Value

Minimum value Maximum value Target value Tooltips

While the Gauge visual will be displayed with any of the field wells filled, it should at least have a field in the Value field well. When you place Total Actual Amount in the Value field well, you will see a visual like in Figure 2.62.

FIGURE 2.62 Gauge visual

The main value is displayed in the center. Since there is no trend axis, the value displayed is the total for all dates in the current filter context.

By default, the visual sets the minimum at 0 and the maximum at double the amount of Value in this case, double the value of Total Actual Amount. As a result, the gauge is exactly half-filled. It is possible to adjust these figures by putting measures into the Minimum Value and Maximum Value field wells, respectively. For example, we can create the following measure and put it into the Maximum Value field well:

Gauge Maximum = 300 * 10 ^ 6

While this measure is hard-coded for example purposes, in real life, this can be a proper dynamic measure. Also, we can use our Target Amount measure in the Target Value field well. Once we add both measures to the visual, it will look like in Figure 2.63.

FIGURE 2.63 Gauge with maximum and target values set

The target amount is now shown as a black needle on the gauge.

The final field well that can be used is Tooltips. This field well can accept multiple measures and is not unique to the Gauge visual; many other visuals have it. When you place a measure into the Tooltips field well, you will be able to see its value when you hover over a data point in the visual. If you put Total Profit in the Tooltips field well and hover over the gauge, the visual will look like the one in Figure 2.64.

FIGURE 2.64 Tooltips

Note that tooltips do not necessarily contain all the measures that are used in a visual. In our case, the Gauge Maximum measure is absent.

MORE INFO TOOLTIPS

Tooltips can be a powerful addition to many visuals. Besides numeric values, they can also display datetime and text measures. For more examples and details on the Tooltip feature, see “Customizing Tooltips in Power BI Desktop” at https://docs.microsoft.com/en-us/power- bi/desktop-custom-tooltips.

Use the format settings to manually set values

Besides using measures in field wells of a Gauge, you can set the minimum, maximum, and target values manually in the Format pane. If you set a value in a field well, you will not be able to override it in the Format pane. For instance, if we keep the Gauge Maximum measure but remove the Target Amount measure and go to the Gauge Axis section in the Format pane, we will be able to set both the minimum and target values. The settings can be seen in Figure 2.65.

FIGURE 2.65 Gauge axis format settings

You can use the Format pane to do the following in the Gauge:

Change the colors of the gauge and the target line

Hide or format the minimum and maximum values, target, and the main value MORE INFO GAUGES AND SINGLE-NUMBER CARDS

For more examples and information on using card visuals and gauges, see “Gauges and single-number cards” at https://docs.microsoft.com/en-us/power-bi/guided-learning/visualizations#step-9.

For a video tutorial on using the Gauge visual, see “Radial gauge charts in Power BI (Tutorial)” at https://docs.microsoft.com/en-us/power- bi/power-bi-visualization-radial-gauge-charts.

Một phần của tài liệu Analyzing and visualizing data by using microsoft power BI (Trang 123 - 130)

Tải bản đầy đủ (PDF)

(396 trang)