Przemyslaw Remin
Przemyslaw Remin

Reputation: 6940

Traffic lights in Power Bi which work also for totals

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?

enter image description here

Edit. Seems to be a dream feature you can vote for. Please do vote for it!

https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/17401381-conditional-formatting-for-total-and-subtotals-in

Upvotes: 4

Views: 16388

Answers (3)

Przemyslaw Remin
Przemyslaw Remin

Reputation: 6940

Since the April 2020 PBI update this is finally possible:

https://powerbi.microsoft.com/en-us/blog/power-bi-desktop-april-2020-feature-summary/#_Conditional_formatting

enter image description here

Upvotes: 1

greggyb
greggyb

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 )

These look like this: red, yellow, and green circles from Unicode codepoints

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:

sample of KPI measure in a table visual

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

Przemyslaw Remin
Przemyslaw Remin

Reputation: 6940

Traffic lights for totals cannot be done by standard means, but there is a workaround. You may achieve something like this:

![enter image description here

The idea is based on the following points:

  1. Have a dictionary for category and add to it value "Total (avg)" or name it according to thy wish.
  2. Uncheck displaying totals in the format pane of the table visual.
  3. Add DAX measure which returns different calculation for ordinary labels and different for "Total (avg)". Use here SWITCH(TRUE()... See examples at the bottom.
  4. For convenience add SortColumn to your category dictionary. So that your "Total (avg)" will always be at the bottom of the table visual, regardless as you name your total. enter image description here
  5. Unfortunately there is no way to set up bold fonts in conditional formatting. You can only play with background and fonts. Do conditional formatting based on rules applied to SortColumn. I grayed out background of "Total (avg)", and I set up fonts to black color. You have to set up the same conditional formatting for every column in a table. enter image description here
  6. In format of table visual set up a slightly grey font for ordinary mortal values. It is done to get more contrast with black fonts for totals set up in previous point.

enter image description here

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.

TrafficLightsForTotals.pbix

Upvotes: 1

Related Questions