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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Subtracting Not Working as Expected

Hello -

 

I am working on subtracting Current Data with Past Data using a unique ID to find the last historic value for each unique item. I have successfully calculated the previous value by using the following DAX function:

 

Previous Data = 
'Table'[Current Data]
    - MAXX(
        FILTER('Table',
            'Table'[Index]
            = EARLIER('Table'[Index]) - 1
            && 'Table'[UID] = EARLIEST('Table'[UID])
        ),
        'Table'[Current Data]
    )

 

 

Now that I have this value, I want to subract the each individual row from 'Table' [Current Data] from 'Table' [Previous Data] to get a delta/change value for each row. I used the following as an example:

 

Delta = 'Table'[Current Data] - 'Table'[Previous Data]

 

 

However, when using the above "Delta" calculation all of the values result as "0", and I cannot understand why this is happening.

Below is an example of what I would expect to happen with the delta calculation:

UIDDateCurrent DataPrevious DataDelta
12/3/2157478532(2785)
22/3/21467221342538
11/5/21853285320
31/3/21941971282291
21/6/2121349024(6890)
21/2/21902490240
312/4/20712871280

 

Thank you in advance for any assistance!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous ,a new column, you can use index in place of date

 

Diff Previous Data =
var _max = maxx(filter( 'Table','Table'[UID] = EARLIEST('Table'[UID]) , 'Table'[Date] < EARLIER('Table'[Date])),[Date])
return
if(isblank(_max) , 0 , [Current Data] -maxx(filter( 'Table','Table'[UID] = EARLIEST('Table'[UID]) , 'Table'[Date] =_max),[Current Data] ) ) 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

This seems to have worked perfectly! Thank you!

amitchandak
Super User
Super User

@Anonymous ,a new column, you can use index in place of date

 

Diff Previous Data =
var _max = maxx(filter( 'Table','Table'[UID] = EARLIEST('Table'[UID]) , 'Table'[Date] < EARLIER('Table'[Date])),[Date])
return
if(isblank(_max) , 0 , [Current Data] -maxx(filter( 'Table','Table'[UID] = EARLIEST('Table'[UID]) , 'Table'[Date] =_max),[Current Data] ) ) 

Helpful resources

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