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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
ferk_23
Frequent Visitor

Iterate automatically trough columns (conditional formatting on matrix table)

Hi,

This is the table created:

ferk_23_0-1699604651044.png

I'm using the following measure to do conditional formatting: 
color =
var _a=CALCULATE(SUM('Table'[Oct'23]),FILTER(ALL('Table'),'Table'[KPI Name]=MAX('Table'[KPI Name]) && 'Table'[Version]="A"))
var _b=CALCULATE(SUM('Table'[Oct'23]),FILTER(ALL('Table'),'Table'[KPI Name]=MAX('Table'[KPI Name]) && 'Table'[Version]="B"))
return IF(_a>= _b,"#1AAB40", "#D64554")

The problem is that instead of Oct'23 I want an automatic way to always have the last month. In other words, now we are in November, we will use the values from the Oct'23 column. In December, the values in the Nov'23 column and so on.

Any tip is welcome. 

Best regards,
Fernando
4 REPLIES 4
ferk_23
Frequent Visitor

Any more suggestions? I haven't managed it yet because I have the months as columns

OguzMavice
Resolver II
Resolver II

Hi @ferk_23 , 

 

The following link can solve your problem; instead of using hard coded "month name" in your sum formula; you should use previous month total sum logic. 

 

https://community.fabric.microsoft.com/t5/Desktop/using-dax-formula-to-calculate-the-previous-month-...

 

I hope it helps you

 

FreemanZ
Super User
Super User

hi @ferk_23 ,

 

The point is to unpivot your data like:

KPI Name, Version, Month, Value

 

then everything becomes natural like:

color =
var _a=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[KPI Name]=MAX('Table'[KPI Name]) && 'Table'[Version]="A"))
var _b=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),'Table'[KPI Name]=MAX('Table'[KPI Name]) && 'Table'[Version]="B"))
return IF(_a>= _b,"#1AAB40", "#D64554")

 

About Unpivot:

https://learn.microsoft.com/en-us/power-query/unpivot-column

 

 

Thank for your help. 

The columns are now unpivot columns, you know how can I filter to the last month?

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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