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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
MrHajiCoolBreez
Frequent Visitor

Getting the Previous Value in a Matrix with 7 rows

I have a Matrix which looks like this

MrHajiCoolBreez_1-1734356474897.png

 

I have 7 Columns in ROWS
"EndOfSnapShotWeek" in the COLUMNS
and "Rev1" and "Rev2" in the VALUES

I want to create two measures that will calculate whether the "Rev1" or "Rev2" VALUES has gone up/down compared to the previous week (EndOfSnapShotWeek column.).
Then I can use that in conditional formatting.
I can handle the conditional formatting I just need help with the DAX.

Sample PBIX file is attached here
Sample PBIX 

1 ACCEPTED SOLUTION

You have interesting data including negative numbers. Calculating a WoW with a mix of positive and negative numbers is extremely subjective.  Make sure you agree with the formula.

 

Here's my (subjective) version:

 

 

Rev1 change = 
var pr1 = CALCULATE(sum(test[Rev1]),DATEADD('Calendar'[Date],-7,DAY))
return divide(sum(test[Rev1])-pr1,abs(pr1),1)

 

 

 

However your x axis is driven by a fact date (end of snapshot week) and not by the dimension date as it should be . You will want to correct that too ( or modify the above formula)

 

lbendlin_0-1734398705158.png

 

lbendlin_1-1734398737855.png

 

View solution in original post

10 REPLIES 10
MrHajiCoolBreez
Frequent Visitor

This works to calculate the differences but I can't use those Visual Calculations Measures in the Conditional Formatting. 

They don't appear in the "which field should we base these on" drop down

MrHajiCoolBreez_0-1734363313022.png

 

Do you have a workaround or an alternative approach to solve my initial problem?

Short of materializing your result into a calculated table? Don't think so.  But worth a try.

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Here is a PBIX file with sample data
Sample PBIX 
I don't have super user access so I can't directly attached a PBIX so I'm using WeTrasfer

With regards to expected output, if you can create 2 measures that I can use in conditional formating that shows the difference between Rev1 and Rev2 with the previous week that would be ideal

You have interesting data including negative numbers. Calculating a WoW with a mix of positive and negative numbers is extremely subjective.  Make sure you agree with the formula.

 

Here's my (subjective) version:

 

 

Rev1 change = 
var pr1 = CALCULATE(sum(test[Rev1]),DATEADD('Calendar'[Date],-7,DAY))
return divide(sum(test[Rev1])-pr1,abs(pr1),1)

 

 

 

However your x axis is driven by a fact date (end of snapshot week) and not by the dimension date as it should be . You will want to correct that too ( or modify the above formula)

 

lbendlin_0-1734398705158.png

 

lbendlin_1-1734398737855.png

 

Thank you for this but the formula for `pr1` isn't quite right.
My bad,  my explanation for expected output wasn't clear.

As you will notice that not every change is being highlighted as red or green.
For example, Rev1 on row 6 should be in green. Value went up from 30527.25 to 30346.50

pr1 = 
var eosw = max(test[EndOfSnapshotWeek])
RETURN CALCULATE(
            sum(test[Rev1]),
            test[EndOfSnapshotWeek]=eosw-7
        )

I require it to match this visual calculation

vcPr1 = PREVIOUS([Rev1], 1, COLUMNS)

As you can see they don't match

MrHajiCoolBreez_1-1734427376701.png

My X axis is driven by the fact table because the active relationship between the fact table and the calendar table is on a different date column in the fact table.

As you can see in my example I included a neutral area of +/- 5%.  Feel free to modify that.

Cool, thanks. All working now
lbendlin
Super User
Super User

use Visual Calculations - particularly PREVIOUS.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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