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
Tizzerbelle
Frequent Visitor

conditional format in matrix based on selected years

I have created an order intake report where the user can select the years they want to compare.

There is a matrix which shows all the months and the selected years with the value

I want to add conditional formatting which shows red if less than the previous year selected and green if greater than.

I can obviousy do this based on the previous year but cannot workout how to do this based on the selected years.

Below is an image of how i want it to work - done in excel where you can add based on the row.  Any ideas how to achieve this?

 

Tizzerbelle_0-1721642189205.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Tizzerbelle ,

 

I thought about it differently and got the answer you wanted:

vtianyichmsft_0-1722477634790.png

vtianyichmsft_1-1722477643987.png

Measure = 
var _current=[Orders Intake]
var _rank=[Measure 2]
var _table=ADDCOLUMNS(ADDCOLUMNS(SUMMARIZE(ALLSELECTED('DateTable'),[FinYear],[Financial_Fiscal_Month_Name]),"order",[Orders Intake]),"rank",[Measure 2])
var _pre=MAXX(FILTER(_table, [rank] =_rank-1 && [Financial_Fiscal_Month_Name] in VALUES(DateTable[Financial_Fiscal_Month_Name])),[order])
RETURN _pre

Measure 2 = RANKX(ALLSELECTED('DateTable'),[FinYear],MAX('DateTable'[FinYear]),ASC,Dense)

Measure 3 = SWITCH(TRUE(),
ISBLANK([Measure]),"black",
[Orders Intake]<=[Measure],"red","green")

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

9 REPLIES 9
Anonymous
Not applicable

Hi @Tizzerbelle ,

 

I made simple samples and you can check the results below:

vtianyichmsft_0-1721702716785.png

vtianyichmsft_1-1721702736954.png

vtianyichmsft_2-1721702769351.png

 

Measure = var _t = CALCULATE(MAX('Table'[Value]),SAMEPERIODLASTYEAR('Table'[Date].[Date]))
RETURN IF(_t>MAX('Table'[Value]),"RED","GREEN")

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

 

Hi

Thank you for your assistance, I have tried to use this but as i am using a measure within the table - i cannot use MAX so i tried this:

ConditionalColPY = var _t = CALCULATE(MAXX(All('DateTable'),[Orders Intake]),SAMEPERIODLASTYEAR(DateTable[PKDate]))
RETURN IF(_t>MAXX(All(DateTable),[Orders Intake]),"RED","GREEN")

As you can see i am using  a related Date table.

 

The conditional formatting just shows green for all rows, which i suspect is due to the MAXX statement.

Any suggestions?

 

I have also tried this:

ConditionalColPY = 
VAR CurrentPeriodValue = [Orders Intake]
VAR LastYearValue = CALCULATE(
    [Orders Intake],
    SAMEPERIODLASTYEAR(ALL(DateTable[PKDate]))
)
RETURN 
IF(
    LastYearValue > CurrentPeriodValue,
    "RED",
    "GREEN"
)

But this shows all rows and columns as red

Anonymous
Not applicable

Hi @Tizzerbelle ,

 

Can you share the sample pbix file you used?

 

Best regards,
Community Support Team_ Scott Chang

@Anonymous  Sure -  here is a pbix with dummy data in

Conditional format report 

 

Anonymous
Not applicable

Hi @Tizzerbelle ,

 

I've been working on this for quite a while and I realized that I misunderstood your question and that you are not necessarily comparing to last year. There doesn't seem to be a way to do this for this kind of variable comparison. Despite slicer filtering the data, the DAX expression is still conditioned on the previous year of the calculation.

 

Best regards,
Community Support Team_ Scott Chang

@Anonymous Ok, Thanks for trying, hopefully Microsoft will add this feature in the future

Anonymous
Not applicable

Hi @Tizzerbelle ,

 

I thought about it differently and got the answer you wanted:

vtianyichmsft_0-1722477634790.png

vtianyichmsft_1-1722477643987.png

Measure = 
var _current=[Orders Intake]
var _rank=[Measure 2]
var _table=ADDCOLUMNS(ADDCOLUMNS(SUMMARIZE(ALLSELECTED('DateTable'),[FinYear],[Financial_Fiscal_Month_Name]),"order",[Orders Intake]),"rank",[Measure 2])
var _pre=MAXX(FILTER(_table, [rank] =_rank-1 && [Financial_Fiscal_Month_Name] in VALUES(DateTable[Financial_Fiscal_Month_Name])),[order])
RETURN _pre

Measure 2 = RANKX(ALLSELECTED('DateTable'),[FinYear],MAX('DateTable'[FinYear]),ASC,Dense)

Measure 3 = SWITCH(TRUE(),
ISBLANK([Measure]),"black",
[Orders Intake]<=[Measure],"red","green")

 

An attachment for your reference. Hope it helps!

 

Best regards,
Community Support Team_ Scott Chang

 

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

Absolutely brilliant - works a treat

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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