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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
sbm
Helper II
Helper II

Conditional formatting based on differences between months in a matrix.

Hello Experts,

 

I want to highlight values based on differences between current months from Jan to Dec. If the value of Jan month is less than value of Feb month then want to highlight Jan value font in red and Feb value in green and so on for each year.

 

Thank you

 

conditional fromatting.PNG

3 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hello @sbm 

This measure should do exactly what you are looking for:

 

Coloring =
VAR FXvalue = [Total Sales]
VAR FXLastMonth =
    CALCULATE (
        SUM ( FactTable[LineTotal] );
        PREVIOUSMONTH ( MasterCalendar[Date] )
    )
RETURN
    SWITCH ( TRUE (); FXvalue < FXLastMonth; "#ff0000"; "#90ee90" )

 

The measure evaluates the value with the value last month and if current month is lower make it red else make it green.

 

Kind regards
Joren Venema

Data & Analytics Consultant
If this reply solved your question be sure to mark this post as the solution to help others find the answer more easily. 

View solution in original post

Greg_Deckler
Community Champion
Community Champion

You will need a Previous Month measure and % Growth measure. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

Assuming you have a measure called MyMeasure that is displaying your value in your matrix you would do something like:

 

 

PreviousMonth = CALCULATE([MyMeasure],PREVIOUSMONTH(Calendar[Date]))

% Growth = ([MyMeasure] - [PreviousMonth) / [PreviousMonth

 

 

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

You would then base your conditional logic on % Growth.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

v-yingjl
Community Support
Community Support

Hi @sbm ,

You can create the following measure:

 

Measure =

var A = CALCULATE(SUM('table'[Sales]))

var B = CALCULATE(SUM('table'[Sales]),DATEADD('Calendar'[Date],-1,MONTH))

return

IF(A < B, "#ff0000","#90ee90")

 

Then in Matrix Format, choose conditional format:

Matrix1.png, enable Background color and select ‘Advanced controls’:

 

Matrix2.png,choose Format by Field value and select previous measure under Based on filed

 

Here is the demo , please try it:

PBIX 

 

Best Regards,

Yingjie Li

 

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
sbm
Helper II
Helper II

Thank you all for this solution.

v-yingjl
Community Support
Community Support

Hi @sbm ,

You can create the following measure:

 

Measure =

var A = CALCULATE(SUM('table'[Sales]))

var B = CALCULATE(SUM('table'[Sales]),DATEADD('Calendar'[Date],-1,MONTH))

return

IF(A < B, "#ff0000","#90ee90")

 

Then in Matrix Format, choose conditional format:

Matrix1.png, enable Background color and select ‘Advanced controls’:

 

Matrix2.png,choose Format by Field value and select previous measure under Based on filed

 

Here is the demo , please try it:

PBIX 

 

Best Regards,

Yingjie Li

 

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Community Champion
Community Champion

You will need a Previous Month measure and % Growth measure. Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

 

Assuming you have a measure called MyMeasure that is displaying your value in your matrix you would do something like:

 

 

PreviousMonth = CALCULATE([MyMeasure],PREVIOUSMONTH(Calendar[Date]))

% Growth = ([MyMeasure] - [PreviousMonth) / [PreviousMonth

 

 

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...

 

You would then base your conditional logic on % Growth.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hello @sbm 

This measure should do exactly what you are looking for:

 

Coloring =
VAR FXvalue = [Total Sales]
VAR FXLastMonth =
    CALCULATE (
        SUM ( FactTable[LineTotal] );
        PREVIOUSMONTH ( MasterCalendar[Date] )
    )
RETURN
    SWITCH ( TRUE (); FXvalue < FXLastMonth; "#ff0000"; "#90ee90" )

 

The measure evaluates the value with the value last month and if current month is lower make it red else make it green.

 

Kind regards
Joren Venema

Data & Analytics Consultant
If this reply solved your question be sure to mark this post as the solution to help others find the answer more easily. 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.