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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply

I need output like this by using measure ( calculate previous row difference)

IMG_20230716_175307.jpg

 

3 ACCEPTED SOLUTIONS

Here is the working DAX

 

TimePlayed_Difference =
    VAR CurrentIndex =MAX( 'Table'[Index])
    VAR CurrentTimePlayed = 'Table'[total]
    VAR PreviousTimePlayed =
        CALCULATE(
            MAX('Table'[TimePlayed]),
            FILTER(
                ALL('Table'),
                'Table'[Index] = CurrentIndex - 1
            )
        )
    RETURN
        IF(
            CurrentIndex = 1,
            CurrentTimePlayed,
            CurrentTimePlayed - PreviousTimePlayed
        )
 
rubayatyasmin_0-1689522847925.png


Did I help? If yes, hit 👍 and accept this answer as a solution. 

 

Thanks


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


View solution in original post

It will change obviously. check the values if it matched with your desired output or not. I can clearly see that it matched. -520 because we do not have row 1 value. Do we? value started from row 2. Mathematically the answer is right.  


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


View solution in original post

For, Inner join - you will get 1 output (inner join takes only matching rows)\

 

for left join - you will get 2 output. (all from left, matching from right)

 

see sql joins

 

rubayatyasmin_0-1689919560632.png

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


View solution in original post

14 REPLIES 14
rubayatyasmin
Super User
Super User

I think you are missing something. Here is the solution file.  

 

 

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


File showing deleted 

Here is the file. On this website, the file is deleted after you download it. 

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


@rubayatyasmin 

IMG_20230721_110602.jpg

2 table (A,B )

A - 3 rows (1,3,1 )

B - 4 rows (1,1,5,1)

 I need output for inner join and left outer join bro

For, Inner join - you will get 1 output (inner join takes only matching rows)\

 

for left join - you will get 2 output. (all from left, matching from right)

 

see sql joins

 

rubayatyasmin_0-1689919560632.png

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


rubayatyasmin
Super User
Super User

Hi, @Karthikgayathri 

 

you can create a custom column. I created sample values like yours. see the screenshot below. 

 

rubayatyasmin_0-1689519163794.png

I think this is what you wanted. 

 

M code is: if [Index] = 1 then [TimePlayed] else [TimePlayed] - #"Added Index"{[Index]-2}[TimePlayed]

 

in PBI report:

 

rubayatyasmin_0-1689519463745.png

do not forget to sort the category column by Index. 

 

Did this post help? If yes, hit 👍 and accept this answer as a solution. 

 

Thanks


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Bro I already used this method in power query. I need another method by using variables or  by using measure or any other performance best method 

Here is the working DAX

 

TimePlayed_Difference =
    VAR CurrentIndex =MAX( 'Table'[Index])
    VAR CurrentTimePlayed = 'Table'[total]
    VAR PreviousTimePlayed =
        CALCULATE(
            MAX('Table'[TimePlayed]),
            FILTER(
                ALL('Table'),
                'Table'[Index] = CurrentIndex - 1
            )
        )
    RETURN
        IF(
            CurrentIndex = 1,
            CurrentTimePlayed,
            CurrentTimePlayed - PreviousTimePlayed
        )
 
rubayatyasmin_0-1689522847925.png


Did I help? If yes, hit 👍 and accept this answer as a solution. 

 

Thanks


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Ok output crt bro but i need 2 nd column previous row value and third column only I need difference ( like below images). In your output both the column denotes difference only. I m struggling mainly to get 2 nd column  as previous row value. Without bringing index column any other way by using earlier function ? 

IMG_20230716_175307.jpg

Here is the second DAX:

 

TimePlayed_Remaining =
    VAR CurrentRowID = MAX('Table'[Index]) // Replace with your unique row identifier
    VAR CurrentTimePlayed = CALCULATE(MAX('Table'[TimePlayed]), 'Table'[Index] = CurrentRowID)
    RETURN
       IF(CurrentRowID = 1, BLANK(), CurrentTimePlayed-[TimePlayed_Difference])
 
rubayatyasmin_0-1689525320378.png

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


  • 16895276663952563035959287646667.jpg

sry for that blur image because my phone camera not working properly.above  image total mismatch ( both prev value and measure  interchange)as well instead of showing 100 in prev value showing 0  wht is the reason . In time played difference column, u mentioned table[total] . total denotes wht ?

Total is a measure for the sum(timePlayed)


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


See total value in output interchanged bro (-520,580)

It will change obviously. check the values if it matched with your desired output or not. I can clearly see that it matched. -520 because we do not have row 1 value. Do we? value started from row 2. Mathematically the answer is right.  


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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