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
mikeminu
Regular Visitor

Conditional Formatting on Matrix based on same measure comparison

Good afternoon everyone,

 

I hope everyone is well and can maybe help me with a problem I am trying to solve.

 

I created a matrix visual with dates on the columns and index names on the rows. I wanted to show the evolution of the index's prices over the years so I created a measure to calculate the price based on the year. If it is a past year then it should be the average of real price, if current year the average of real + future price and if future year then just the average of the expected future prices. So far, so good and I ended with a table like this: (simplified for sharing purposes)

 

 20212022202320242025
Index A0.41.10.70.60.9
Index B2.14.75.14.93.2
Index C1.31.41.50.91.3

 

Then I thought it would be nice to add some icon conditional formatting as a visual aid to indicate if the price for each index increased or decreased compared to the previous year. This is where things started to get more complicated. Since all the values come from the same measure I couldnt easily compare them. I tried creating a new measure to compare each value with the one on the previous column and return a value from -1 to 1 to then apply the conditional formatting based on this measure, but I cannot seem to find a way to effectively call and compare the columns.

 

Here is the measure I tried to create:

 

mikeminu_0-1733409592184.png

Would really appreciate some help on this matter!

 

Many thanks in advance,

Miguel 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Thanks for the reply from lbendlin, please allow me to provide another insight.
Hi @mikeminu ,

Please refers to the following steps.

Below is my testing data table.

vdengllimsft_0-1733462031608.png

 

Create a date table and establish a relationship with the source table.

DimDate = ADDCOLUMNS(
    CALENDAR(MIN('Table'[Date]),MAX('Table'[Date])),
    "Year", YEAR([Date])
)

vdengllimsft_1-1733462139191.png


Use the following measure to set the conditional format of the matrix values.

Measure = 
VAR SelectedYear = SELECTEDVALUE(DimDate[Year])

VAR CurrentYearValue = CALCULATE([Sum of price], DimDate[Year]=SelectedYear)
VAR PreviousYearValue = CALCULATE([Sum of price], DimDate[Year]= SelectedYear-1)
RETURN
SWITCH(
    TRUE(),
    CurrentYearValue>PreviousYearValue,1,
    CurrentYearValue<PreviousYearValue,-1,
    0
)


The final result is as follows. Hopefully it will meet your needs.

vdengllimsft_2-1733462403027.png

 

Please see the attached pbix for reference.

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

2 REPLIES 2
Anonymous
Not applicable

Thanks for the reply from lbendlin, please allow me to provide another insight.
Hi @mikeminu ,

Please refers to the following steps.

Below is my testing data table.

vdengllimsft_0-1733462031608.png

 

Create a date table and establish a relationship with the source table.

DimDate = ADDCOLUMNS(
    CALENDAR(MIN('Table'[Date]),MAX('Table'[Date])),
    "Year", YEAR([Date])
)

vdengllimsft_1-1733462139191.png


Use the following measure to set the conditional format of the matrix values.

Measure = 
VAR SelectedYear = SELECTEDVALUE(DimDate[Year])

VAR CurrentYearValue = CALCULATE([Sum of price], DimDate[Year]=SelectedYear)
VAR PreviousYearValue = CALCULATE([Sum of price], DimDate[Year]= SelectedYear-1)
RETURN
SWITCH(
    TRUE(),
    CurrentYearValue>PreviousYearValue,1,
    CurrentYearValue<PreviousYearValue,-1,
    0
)


The final result is as follows. Hopefully it will meet your needs.

vdengllimsft_2-1733462403027.png

 

Please see the attached pbix for reference.

Best Regards,
Dengliang Li

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

lbendlin
Super User
Super User

You cannot measure a measure directly. Either materialize it first, or create a separate measure that implements the entire business logic.

 

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.