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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Calculate difference between to rows in the same column

I am trying to calculate the variance of projects, over different periods. Periods are referenced as P1, P2,...

The user should be able to pick the periods that they want to compare and see the projects listed

 

PeriodObject       WIPIndexIndex.1
FY22 P01PRJ28,90601
FY22 P02PRJ3,90612
FY22 P01PRJ25,50601
FY22 P02PRJ28,00012

 

I have tried a dax formula, but I can't find one that has more than one filter.

 

My DAX:

Variance = VAR DIFF = WIP[ WIP]-

CALCULATE(sum(WIP[ WIP]), 

FILTER('WIP', WIP[Index1]=EARLIER(WIP[Index])))

return IF(DIFF=VALUE(WIP[ WIP]), 0,

DIFF

)

 

Can you help?

6 REPLIES 6
danextian
Super User
Super User

Hi @Anonymous,

 

What do you mean by "more than one filter?" Also, are you trying to get the difference between two succeeding periods for every object? If that is the case, try this formula as a calc column

Diff = 
VAR _prev =
    CALCULATE (
        SUM ( Data[WIP] ),
        FILTER (
            ALL ( Data ),
            Data[Index] < EARLIER ( Data[Index] )
                && Data[Object] = EARLIER ( Data[Object] )
        )
    )
RETURN
    Data[WIP] - _prev









Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Thank you for this.

Sorry but it didn't work.

I'm not sure what is doing.

An object where variance should be 0, shows different figures

Please post your expected result.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

PeriodObject       WIPIndexIndex.1Variance
FY22 P01PRJ500010
FY22 P01PRJ2550010
FY22 P02PRJ6001250
FY22 P02PRJ6501250
FY22 P03PRJ7002350
FY22 P03PRJ280023100

Hi @Anonymous ,


Given that there are repeating indices in your data, what is your logic in calculating the variance in the highlighted cells below? What column can be used that will make each row unique  and will indicate that a  row comes before the other?

danextian_0-1660550349725.png

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Thank you so much,

 

There was an error in that table. 

Can you look at this one:

PeriodObject       WIPIndexIndex.1Variance
FY22 P01PRJ500010
FY22 P02PRJ60012100
FY22 P03PRJ6502350
FY22 P01PRJ2700010
FY22 P02PRJ255012(150)
FY22 P03PRJ280023250

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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