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
mtrevisiol
Helper V
Helper V

How to calculate a measure referred to the previous month

Hi everyone.

I've got a matrix which shows the margin for each month of 2018, 2019, 2020, 2021:

mtrevisiol_0-1626440669299.png

 

Since I want to use the conditional formatting, I would like to compare the margins from one month to another in order to apply different colours to the cells:

  • if the margin of this month is higher than the margin of the previous month --> green
  • if the margin of this month is lower than the margin of the previous month --> red

 

Margins are calculated using a different measure for each year (only the year value changes):

Margin 2021 = CALCULATE(
         SUM('Sales'[Value]) - SUM('Sales'[Total Cost]),2),
         VALUE('Sales'[DATA_doc_YY])=YEAR(NOW()),
         'Sales'[DataType] = "Billed")
 
Thank you for the help!
1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @mtrevisiol ,

 

You could refer to this blog to create a measure of the previous month.

https://www.sqlbi.com/articles/comparing-with-previous-selected-time-period-in-dax/ 

Then create a condition measure to set the background.

condition = IF(Sales[Sales PM]>Sales[Sales Amount],"red","green")

Vlianlmsft_0-1626767478449.pngVlianlmsft_1-1626767509398.png

 

 

Best Regards,
Liang
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

2 REPLIES 2
V-lianl-msft
Community Support
Community Support

Hi @mtrevisiol ,

 

You could refer to this blog to create a measure of the previous month.

https://www.sqlbi.com/articles/comparing-with-previous-selected-time-period-in-dax/ 

Then create a condition measure to set the background.

condition = IF(Sales[Sales PM]>Sales[Sales Amount],"red","green")

Vlianlmsft_0-1626767478449.pngVlianlmsft_1-1626767509398.png

 

 

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

CNENFRNL
Community Champion
Community Champion

Author another measure to calculate MoM margin difference to be used in the "conditional formatting" functionality.


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

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.