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

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

Reply
Analitika
Post Prodigy
Post Prodigy

Substraction calculation between values in Power Bi

Hello,

 

I would like to ask how calculate difference between values which are in different rows and columns.

My query is: 

 

Column =
VAR _0 = MINX(FILTER('x','x'[date]> EARLIER('x'[date]) && 'x'[ID]= EARLIER('x'[ID])),[date])
VAR _1 = MAXX(FILTER('x','x'[date] =_1 && 'x'[ID]= EARLIER('x'[ID]) ),[cre])
return 

if('x'[deb] <> 0,_1 - 'x'[deb], blank())

 

 

My data sample is:

Analitika_0-1634200766651.png

My output is :

Analitika_1-1634200879406.png

Expected result is:

Analitika_2-1634200937656.png

Seems results don't match because in difference column values are different (0.87!-3289.13)

So how to solve this issue?

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @Analitika ,

Based on your formula and your expected output, you could change '>' to '=' in the formula like this:

Difference = 
VAR _0 =
    MINX (
        FILTER (
            'x',
            'x'[DATE] = EARLIER ( 'x'[DATE] )
                && 'x'[ID] = EARLIER ( 'x'[ID] )
        ),
        [DATE]
    )
VAR _1 =
    MAXX ( FILTER ( 'x', 'x'[DATE] = _0 && 'x'[ID] = EARLIER ( x[ID] ) ), [CRE] )
RETURN
    IF ( 'x'[DET] <> 0, _1 - 'x'[DET], BLANK () )

vyingjl_0-1634708733965.png

 

Best Regards,
Community Support Team _ Yingjie Li
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-yingjl
Community Support
Community Support

Hi @Analitika ,

Based on your formula and your expected output, you could change '>' to '=' in the formula like this:

Difference = 
VAR _0 =
    MINX (
        FILTER (
            'x',
            'x'[DATE] = EARLIER ( 'x'[DATE] )
                && 'x'[ID] = EARLIER ( 'x'[ID] )
        ),
        [DATE]
    )
VAR _1 =
    MAXX ( FILTER ( 'x', 'x'[DATE] = _0 && 'x'[ID] = EARLIER ( x[ID] ) ), [CRE] )
RETURN
    IF ( 'x'[DET] <> 0, _1 - 'x'[DET], BLANK () )

vyingjl_0-1634708733965.png

 

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

VahidDM
Super User
Super User

Hi @Analitika 

 

Understand you wnat to calculate the difference between CRE and DET when the DET value is not Zero.

For this you can add a column with this code:

 

Column =
if([DET] <> 0,[CRE] - [DET], blank())

 

 

If I got your point in the wrong way, please add more details with a sample of your data.

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.

Appreciate your Kudos!!

 

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.