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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
leylarm
Frequent Visitor

Subtract one row from the prior

Hello

I have 3 columns :

Index  (1,2,3,4,5,..,365)

Days (1May, 2 May, ..., Apr 30) - 365days

Month(May2017, May 2017, ,..., April 2018) - 365

Numbers (5454,2187,15487,48797,...,26554)

 

I want the find the difference, like (in index)

1-1= 0

2-1=2187-5454

3-2= 15487-2187

and so on

 

i found a Dax script:

Diff =
VAR Index = 'Table'[Index]
VAR Reference = 'Table'[Month].[Day]
VAR PrevCreditP =
CALCULATE (
FIRSTNONBLANK ( 'Table'[Numbers], TRUE () ),
FILTER ( 'Table', 'Table'[Index] = Index - 1 && 'Table'[Month].[Day] = Reference )
)
RETURN
IF (
ISBLANK ( PrevCreditP ),
BLANK (),
'Table'[Credit Provision] - PrevCreditP
)

 

But it works not properly. Despite the correct numbers in each columns ( in power bi and excel), their sum - are different.

Kindly ask to help me

 

1 ACCEPTED SOLUTION
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @leylarm,

 

Please create a calculated column with the formula below.

 

diff =
VAR current_index = 'Table'[Index]
VAR prior =
    CALCULATE (
        SUM ( 'Table'[Numbers] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] = current_index - 1 )
    )
RETURN
    'Table'[Numbers] - IF ( ISBLANK ( prior ), 'Table'[Numbers], prior )

Or measure with the foemula below.

 

Measure =
VAR current_index =
    MAX ( 'Table'[Index] )
VAR prior =
    CALCULATE (
        SUM ( 'Table'[Numbers] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] = current_index - 1 )
    )
RETURN
    MAX ( 'Table'[Numbers] )
        - IF ( ISBLANK ( prior ), MAX ( 'Table'[Numbers] ), prior )

Here is the result.

 

result.PNG

 

In addition, you could refer to the similar thread.

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @leylarm,

 

Please create a calculated column with the formula below.

 

diff =
VAR current_index = 'Table'[Index]
VAR prior =
    CALCULATE (
        SUM ( 'Table'[Numbers] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] = current_index - 1 )
    )
RETURN
    'Table'[Numbers] - IF ( ISBLANK ( prior ), 'Table'[Numbers], prior )

Or measure with the foemula below.

 

Measure =
VAR current_index =
    MAX ( 'Table'[Index] )
VAR prior =
    CALCULATE (
        SUM ( 'Table'[Numbers] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Index] = current_index - 1 )
    )
RETURN
    MAX ( 'Table'[Numbers] )
        - IF ( ISBLANK ( prior ), MAX ( 'Table'[Numbers] ), prior )

Here is the result.

 

result.PNG

 

In addition, you could refer to the similar thread.

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thank you very much!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Kudoed Authors