cancel
Showing results 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

## 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
RETURN
PercMaxWeek-PercLast1Week``````

But probably the code

``MAX(DateTable[week])-1)``

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?

Thanks.

5 REPLIES 5
Super User

Helper V

Super User

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

Helper V

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..

Super User

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)

Announcements

#### 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.

#### Power BI Monthly Update - February 2024

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

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

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

Top Solution Authors
Top Kudoed Authors