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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Pan_Forex
Helper III
Helper III

row minus previous row

Hello, I am trying to count the difference in points between the latest ID and the previous one for each employee. I have a very simple bug somewhere and I can't find it... 

id        employe         points        output
200A100-10
200B15010
200C13050
190A110 
190B14040
190C8030
180C50 
180B100 

 

output =
VAR CurrentPoints = 'Table'[points]
VAR PreviousPoints =
    CALCULATE(
        MAX('Table'[points]),
        FILTER(
             'Table',
            'Table'[emloye] = EARLIER('Table'[emloye]) &&
            'Table'[id] < EARLIER('Table'[id])
            )
        )
   
RETURN
    IF(ISBLANK('Table'[id]), BLANK(), CurrentPoints - PreviousPoints)


My function returns different values than the output from the table as if it was looking for the maximum value from all rows.

1 ACCEPTED SOLUTION
AntrikshSharma
Super User
Super User

@Pan_Forex 

Total Points = SUM ( pan[points] )
Output = 
VAR PreviousValue = 
    CALCULATE ( 
        [Total Points],
        OFFSET ( 
            -1,
            ALL ( pan[employee], pan[id] ),
            ORDERBY ( pan[id], ASC ),
            PARTITIONBY ( pan[employee] )
        )
    )
VAR CurrentValue = 
    [Total Points]
VAR GroupingByID = 
    ISINSCOPE ( pan[id] )
VAR Result = 
    IF ( 
        NOT ISBLANK ( PreviousValue )
            && GroupingByID,
        CurrentValue - PreviousValue
    )
RETURN
    Result

AntrikshSharma_0-1718397223228.png

 

View solution in original post

7 REPLIES 7
AntrikshSharma
Super User
Super User

@Pan_Forex 

Total Points = SUM ( pan[points] )
Output = 
VAR PreviousValue = 
    CALCULATE ( 
        [Total Points],
        OFFSET ( 
            -1,
            ALL ( pan[employee], pan[id] ),
            ORDERBY ( pan[id], ASC ),
            PARTITIONBY ( pan[employee] )
        )
    )
VAR CurrentValue = 
    [Total Points]
VAR GroupingByID = 
    ISINSCOPE ( pan[id] )
VAR Result = 
    IF ( 
        NOT ISBLANK ( PreviousValue )
            && GroupingByID,
        CurrentValue - PreviousValue
    )
RETURN
    Result

AntrikshSharma_0-1718397223228.png

 

Kaviraj11
Super User
Super User

How large is the dataset?

 

Here are the articles to resolve the memory issues.

 How to Fix Memory Allocation Error in Power BI Desktop - Monocroft




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

Proud to be a Super User!





It is not large, as it has about 100,000 records

Would need more information to understand the root cause. Are you getting the error after creating a calculated column? and make sure the dataset is sorted as well




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

Proud to be a Super User!





Pan_Forex_1-1718388740132.png

 

I solved this problem and as you can see in the picture sometimes it counts right and sometimes wrong. What could this be due to?

Kaviraj11
Super User
Super User

Hi,

 

Create a new column to calculate the difference in points between the current row and the previous row for the same employee:

Points Difference =
VAR CurrentPoints = [points]
VAR PreviousPoints =
    CALCULATE (
        MAX ( 'Table'[points] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[id] < EARLIER ( 'Table'[id] )
            && 'Table'[employee] = EARLIER ( 'Table'[employee] )
        )
    )
RETURN
IF ( NOT ISBLANK ( PreviousPoints ), CurrentPoints - PreviousPoints )

Kaviraj11_0-1718374101262.png

 




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

Proud to be a Super User!





Thanks for your answer 🙂 It should work but yet a message about insufficient memory appears. 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.