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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Erick24
Frequent Visitor

Subtract the value of the column to the left from the higher value of a column

Hello, I hope you can help me with the following:

 

1) When the row number in the table consumption is 1 must substract the quantity of the ID of the table quantity less consumption.

2) When the row number is different to 1 must substrat the higher value of the column project less the value of the column consumption like is in the image below:

 

Example of my Power Bi.

Consumption table

Erick24_2-1734621701501.png

 

Quantity table:

Erick24_3-1734621716624.png

 

 

 

Example in Excel:

Erick24_1-1734621266238.png

 

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @Erick24 ,

You can create a calculated column as below to get it, please find the details in the attachment.

Column =
VAR _qty =
    CALCULATE (
        MAX ( 'Quantity'[Quantity] ),
        FILTER ( 'Quantity', 'Quantity'[ID] = 'Consumption'[ID] )
    )
VAR _accsum =
    CALCULATE (
        SUM ( 'Consumption'[CONSUMPTION] ),
        FILTER (
            'Consumption',
            'Consumption'[ID] = EARLIER ( 'Consumption'[ID] )
                && 'Consumption'[ROW NUM] <= EARLIER ( 'Consumption'[ROW NUM] )
        )
    )
RETURN
    _qty - _accsum

vyiruanmsft_0-1734658712028.png

Best Regards

Community Support Team _ Rena
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-yiruan-msft
Community Support
Community Support

Hi @Erick24 ,

You can create a calculated column as below to get it, please find the details in the attachment.

Column =
VAR _qty =
    CALCULATE (
        MAX ( 'Quantity'[Quantity] ),
        FILTER ( 'Quantity', 'Quantity'[ID] = 'Consumption'[ID] )
    )
VAR _accsum =
    CALCULATE (
        SUM ( 'Consumption'[CONSUMPTION] ),
        FILTER (
            'Consumption',
            'Consumption'[ID] = EARLIER ( 'Consumption'[ID] )
                && 'Consumption'[ROW NUM] <= EARLIER ( 'Consumption'[ROW NUM] )
        )
    )
RETURN
    _qty - _accsum

vyiruanmsft_0-1734658712028.png

Best Regards

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

This is exactly what I was looking for. Thank you very much. 😊

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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