Forum Discussion

jaryszek's avatar
jaryszek
Super User
10 months ago
Solved

Conditional formatting based on value, not a category name for line chart

Hello Guys,

I have a way of standarizing all colors on donuts charts using 2 measures:

 

-- Works at Category and Subcategory levels, blanks elsewhere
Rank (Current Axis) :=
VAR Result =
    IF (
        ISINSCOPE ( Dim_Meter[MeterSubCategory] ),
            RANKX (
                ALLSELECTED ( Dim_Meter[MeterSubCategory] ),
                CALCULATE ( [Total Amortized Cost] ),
                ,
                DESC,
                DENSE
            ),
        IF (
            ISINSCOPE ( Dim_Meter[MeterCategory] ),
            RANKX (
                ALLSELECTED ( Dim_Meter[MeterCategory] ),
                CALCULATE ( [Total Amortized Cost] ),
                ,
                DESC,
                DENSE
            ),
            BLANK ()
        )
    )
RETURN Result

 

DAX 
Color by Rank :=
VAR r = [Rank (Current Axis)]
RETURN
SWITCH (
    TRUE(),
    ISBLANK ( r ) || r > 5, "#B3B3B3",
    r = 1, "#E81123",
    r = 2, "#107C10",
    r = 3, "#0078D4",
    r = 4, "#FFB900",
    r = 5, "#8E8CD8"
)


And this is working like a charm. 
After implementing those 2 measures I change donut chart into bar chart, added color by rank measure and switched again to donut. Eveyrthing works great!

But what about line chart and conditional formatting like that?
How to create a proper SWITCH for it using DAX?


I am attaching example pbix:
https://drive.google.com/file/d/14lpEWK-MQ6JMU5_15WVh8Gv22AiGvdpR/view?usp=sharing

Best wishes,
Jacek

 






  • To the best of my knowledge, no. However, you could try Power BI’s built-in Python support for this. Keep in mind that Python visuals have lots of limitations—for example, (they do not support tooltip hovering, etc.)

     

    Below is a Python visual example I have created, and I’ve attached the PBIX file for your reference.

     

    For this to work, you need to have Python installed on your machine: Python setup tutorial,  or you can publish the PBIX file to the Power BI Service to view the visual. 

     

5 Replies