Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
BOti62
Regular Visitor

Conditional Formatting Colours do not work for for Card visualisation

Hi All

In the screenshot below I have created a Power BI Card visual which changes value based on what I select in the Comparisons Parameter.  

 

 

 

Below is the DAX code which I used:

ColourForComparisonsParameter =

VAR _sel = SELECTEDVALUE(‘Time Parameters’ [Time Parameters Fields])

VAR _var = SWITCH (

TRUE()

, CONTAINSSTRING(_sel, “Yesterday”), [Latest Total Errors] – [Total_Errors_1_Day_Ago]

, CONTAINSSTRING(_sel, “7 Days”), [Latest Total Errors] – [Total_Errors_7_Day_Ago]

, CONTAINSSTRING(_sel, “7 Days”), [Latest Total Errors] – [Total_Errors_30_Day_Ago]

, [Latest Total Errors] – [Total_Errors_365_Day_Ago]

)

RETURN

SWITCH(

TRUE()

, _var < 0, “Green”

, _var > 0, “Red”

, “Black”

)

 

So the Dax code is saying that if I select a value in the Comparisons parameter e.g Yesterday then the calculation it should do is Latest Total Errors (Measure) - Total Errors 1 Day Ago (Measure) and if this value is greater than 0 then make it red and if less than 0 then make it green. 

 

However the colours for when I click on vs 7 Days Ago and vs 30 Days Ago dont match and show the opposite of what I want, whilst vs Yesterday and vs Last Year work fine show the right colours. For example 0.02% and 102 should be in green not red.

 

Is anyone able to help please.

2 REPLIES 2
amitchandak
Super User
Super User

@BOti62 , is this calculation used for showing 102 ?

SWITCH (

TRUE()

, CONTAINSSTRING(_sel, “Yesterday”), [Latest Total Errors] – [Total_Errors_1_Day_Ago]

, CONTAINSSTRING(_sel, “7 Days”), [Latest Total Errors] – [Total_Errors_7_Day_Ago]

, CONTAINSSTRING(_sel, “7 Days”), [Latest Total Errors] – [Total_Errors_30_Day_Ago]

, [Latest Total Errors] – [Total_Errors_365_Day_Ago]

)

 

I doubt some issues with calculation


Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi amitchandak

THanks for getting back to me

The below DAX formula is what I used to get 102:

 

LatestErrors vs 7dayago =

VAR _var = [LatestTotalErrors] – [Total_Errors_7_Day_Ago]

VAR _pctchange = var/[Total_Errors_7_Day_Ago]

VAR _pctFormatted = IF(ABS(_pctchange) >=1, SIGN(_pctchange) * 1, _pctchange)

VAR

    _direction =

         SWITCH(

               TRUE()

             , _var > 0, “🔼

          , _var < 0, “🔽

          , _var “️”

)

RETURN

_direction & FORMAT(_pctchange, “##0.0##%”) & “ | “ & _direction & FORMAT(_var, “0”)

 

The below measure is what I used within the above measure for LatestTotalErrors.

 

LatestTotalErrors =

VAR LastDateStamp = CALCULATETABLE(LASTNONBLABK(‘Calender’[Date],0),ALL (‘DateQualityDashboard’) )

RETURN (

CALCULATE (SUM (‘DataQualityDashboard’[ErrorCount]),

KEEPFILTERS (LastDateStamp ) ) + 0)

 

Below is some sample data

 

DateError Count
11-Jan-24324
11-Jan-24414
04-Jan-24324
04-Jan-24363

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors