Reputation: 6940
How to make traffic light in table visual which works also for totals? Let's say our KPI is some sort of a ratio or a share like GDP per capita by countries, or the difference from the budget by stores. It is interesting to have traffic lights for individual categories but it would be even more interesting to have a traffic light for summary of all categories.
I followed and example shown here: The idea is based on adding a DAX measure:
TrafficLight = UNICHAR(11044)
And then we set up conditional formatting for traffic lights based on other column or measure. But the conditional formatting seems not to affect totals. How to have a traffic light which also shows red, yellow, green color for totals?
Edit. Seems to be a dream feature you can vote for. Please do vote for it!
Upvotes: 4
Views: 16388
Reputation: 6940
Since the April 2020 PBI update this is finally possible:
Upvotes: 1
Reputation: 3798
You're halfway there with UNICHAR()
. The next step is to give up on the conditional formatting in Power BI. Here are three Unicode characters that you can use for traffic lights. I sourced them from Emojipedia. These three are "red circle", "yellow circle", and "green circle".
RedLight = UNICHAR ( 128308 )
YellowLight = UNICHAR ( 128993 )
GreenLight = UNICHAR ( 128994 )
Now that you have measures returning the right colors, you can reference these in another measure that has your range logic. Here's a sample. I've used your measure names. My image is from a demo workbook with different names.
Sales Amount KPI =
VAR SalesAmount = [SalesAmount]
RETURN
SWITCH (
TRUE (),
ISBLANK ( SalesAmount ), BLANK (),
SalesAmount < 50, [GreenLight],
SalesAmount < 150, [YellowLight],
[RedLight]
)
This leverages SWITCH
, wherein we do something only slightly clever. SWITCH
tests its first argument for equality with subsequent arguments. By testing against TRUE ()
, we can have arbitrary boolean expressions. The value following the matching expression is returned.
The first test, ISBLANK
is to guard against displaying this KPI measure for all dimension values. It will only return a value for dimension attributes that have data for the base measure.
Then it's just a series of inequality tests to define my KPI boundaries, as you would do in conditional formatting.
You can go as complex as you want. Here's what it looks like:
Since this is just a regular measure returning a regular text value, you can use this anywhere that displays text including cards, multicards, tooltips, tables, and matrices. There's nothing special about the grand total level for this measure.
Upvotes: 3
Reputation: 6940
Traffic lights for totals cannot be done by standard means, but there is a workaround. You may achieve something like this:
The idea is based on the following points:
SWITCH(TRUE()...
See examples at the bottom.Here are DAX measures I used: Measure:
KPI = SWITCH(TRUE(),
MAX(DimCountry[SortColumn]) = 999, [GDP per capita Total],
[GDP per capita]
)
And measure for total:
GDP per capita Total = CALCULATE([GDP per capita], ALL(FactTable))
For those of you who have read to this point, here is pbix file for download.
Upvotes: 1