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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

Conditionally format matrix cell value based on previous year value

Hi

 

I've been searching for a solution to my request but can't seem to find one that works unfortunately so reaching out for help!

 

I have a simple matrix table with categories as row titles and year as column headings. The values are a simple percentage measure i've created with a particular population and the year is based on a year column within the data table

 

What i would like to do is simply colour the background of a cell based on the previous year value.

 

1. if value is greater than previous year, colour green

2. if the same, colour yellow

3. if below, colour red

 

Below is my example matrix table

 

Pic.png

 

Any help greatly appreciated

2 ACCEPTED SOLUTIONS

error was in the end of script 

 

color =
var _PrevYear =CALCULATE([measure],SAMEPERIODLASTYEAR('Calendar '[Date]))
var _result =SWHITCH (TRUE(),
[measure]>_PrevYear,"green",
[measure]=_PrevYear,"yellow",
"red")

 

 

if you problem is resiolved please mark topic as resolved )

and click cudoes fror me )

If my message helped solve your issue, please mark it as Resolved! If it was helpful, consider giving it a Kudos!

View solution in original post

Anonymous
Not applicable

It wasn't actually the " that was causing the problem. The syntax needed to use 'return' instead of another variable.

 

color =
var _PrevYear =CALCULATE([measure],SAMEPERIODLASTYEAR('Calendar '[Date]))
Return
SWITCH (TRUE(),

[measure]>_PrevYear,"green",
[measure]=_PrevYear,"yellow",
"red")

 

Many thanks for your help as everything is now working as i'd hoped 

 

View solution in original post

5 REPLIES 5
SolomonovAnton
Solution Supplier
Solution Supplier

hello 

 

you should create date table

 

 

Calendar = CARENDARAUTO()

 

 

after it link  the Calendar  table with the FAct table you should create measure

 

 

color =
var _PrevYear =CALCULATE([measure],SAMEPERIODLASTYEAR('Calendar '[Date]))
var _result =SWHITCH (TRUE(),
[measure]>_PrevYear,"green",
[measure]=_PrevYear,"yellow",
"red)

 

 

 

there [measure] - it is the measure which calculated percent for each year

cafer it create conditonal formating based on the [color] measure
see manual about conditional formating

 

 

if you problem is resiolved please mark topic as resolved )

and click cudoes fror me )

If my message helped solve your issue, please mark it as Resolved! If it was helpful, consider giving it a Kudos!
Anonymous
Not applicable

Many thanks for the reply

 

But there appears to be a slight problem with the measure. It's giving me a snytax error to do with ')' but i can't see where the issue would be as everything appears to be closed off correctly

error was in the end of script 

 

color =
var _PrevYear =CALCULATE([measure],SAMEPERIODLASTYEAR('Calendar '[Date]))
var _result =SWHITCH (TRUE(),
[measure]>_PrevYear,"green",
[measure]=_PrevYear,"yellow",
"red")

 

 

if you problem is resiolved please mark topic as resolved )

and click cudoes fror me )

If my message helped solve your issue, please mark it as Resolved! If it was helpful, consider giving it a Kudos!
Anonymous
Not applicable

It wasn't actually the " that was causing the problem. The syntax needed to use 'return' instead of another variable.

 

color =
var _PrevYear =CALCULATE([measure],SAMEPERIODLASTYEAR('Calendar '[Date]))
Return
SWITCH (TRUE(),

[measure]>_PrevYear,"green",
[measure]=_PrevYear,"yellow",
"red")

 

Many thanks for your help as everything is now working as i'd hoped 

 

I am glade to hear it 🙂

 

please mark topic as resolved )

and click cudoes fror me )

If my message helped solve your issue, please mark it as Resolved! If it was helpful, consider giving it a Kudos!

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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