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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Helper V
Helper V

Delta value between 2 weeks

Hi there. 

I'm trying to calculate the delta% between th last week agree with my filter anche le last-1 week.


I try with this:



Delta%PerditaLast = 
VAR PercMaxWeek= if(MAX(DateTable[week]) > DateTable[ThisWeek],calculate('SAPProdEvent-2'[%Perdita_RIL], FILTER(DateTable,DateTable[week]=DateTable[ThisWeek])),calculate('SAPProdEvent-2'[%Perdita_RIL], FILTER(DateTable,DateTable[week]=MAX(DateTable[week]))))
VAR PercLast1Week = if(MAX(DateTable[week]) > DateTable[ThisWeek],calculate('SAPProdEvent-2'[%Perdita_RIL], FILTER(DateTable,DateTable[week]=DateTable[ThisWeek])),calculate('SAPProdEvent-2'[%Perdita_RIL], FILTER(DateTable,DateTable[week]=(MAX(DateTable[week])-1))))
//VAR Delta = PercMaxWeek-PercMinWeek



But probably the code 




is not correct. 


Also it gives me an error: cannot compare a text type and a number type. 

Actually, I just copy the formula that I use to calcolate the %Delta with another percentage measure, but in that case i calculate the MAX and the MIN week of my filter. 


Some suggestion? 


Super User
Super User

Please show a couple of rows of your "DateTable" table.



var thisweek = max(DateTable[Week])
var prevweek = calculate(max(DateTable[Week]),all(DateTable),DateTable[Week])<thisweek)

Thanks for your reply, I think that I can use this to my case. 

Instead of this solution, what if I want to show the difference between a week and the previous one?


For example, in WK15 I want to show the difference between WK 15 and WK14, in WK 14 the difference between WK 14 and WK 13.. 

you would use the same approach. Remember that "MAX"  is dependent on the current filter context, and it has a different meaning in different parts of your visual. That way you can write a single measure that can  compare a value with its "previous"  incarnation.  (Note that the new windowing functions can also be used if you are looking for alternatives)

Helpful resources

Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.