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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
v-denglli-msft
Community Support
Community Support

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
v-denglli-msft
Community Support
Community Support

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.