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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Analitika
Post Prodigy
Post Prodigy

How to substract values which are in different rows in Power BI?

   

I wanted to substract CRE-DET exactly 8000-6000  but getting very strange wrong answers. 

 

Analitika_0-1634130868708.png

 

 

Here I am using formula

New Measure =
VAR a = CALCULATE(SUM('x'[cre]),FILTER(ALL('x'),'x'[date]<MAX('x'[date])))+0
RETURN SUM('xj'[deb])-a
1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Analitika 

You need to calculate CRE and DET separately. Add more conditions to the filter code of the calculation. Here I add DTE = 0 when calcualte CRE and add CRE = 0 when calcualte DET.

Substract = 
VAR _CRE =
    CALCULATE (
        SUM ( x[CRE] ),
        FILTER (
            ALL ( x ),
            x[ID] = MAX ( x[ID] )
                && x[OBJ_ID] = MAX ( x[OBJ_ID] )
                && x[DET] = 0
        )
    )
VAR _DET =
    CALCULATE (
        SUM ( x[DET] ),
        FILTER (
            ALL ( x ),
            x[ID] = MAX ( x[ID] )
                && x[OBJ_ID] = MAX ( x[OBJ_ID] )
                && x[CRE] = 0
        )
    )
RETURN
    _CRE - _DET

Result is as below.

1.png

 

Best Regards,
Rico Zhou

 

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

1 REPLY 1
v-rzhou-msft
Community Support
Community Support

Hi @Analitika 

You need to calculate CRE and DET separately. Add more conditions to the filter code of the calculation. Here I add DTE = 0 when calcualte CRE and add CRE = 0 when calcualte DET.

Substract = 
VAR _CRE =
    CALCULATE (
        SUM ( x[CRE] ),
        FILTER (
            ALL ( x ),
            x[ID] = MAX ( x[ID] )
                && x[OBJ_ID] = MAX ( x[OBJ_ID] )
                && x[DET] = 0
        )
    )
VAR _DET =
    CALCULATE (
        SUM ( x[DET] ),
        FILTER (
            ALL ( x ),
            x[ID] = MAX ( x[ID] )
                && x[OBJ_ID] = MAX ( x[OBJ_ID] )
                && x[CRE] = 0
        )
    )
RETURN
    _CRE - _DET

Result is as below.

1.png

 

Best Regards,
Rico Zhou

 

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.