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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Measure to subtract row value from most recent value

Hi all,

I have a table that contains the last 5 tvalues for each Prod_ID ordered by date desc.

Capture 1.PNG

I need help with a measure that will calculate the value at a row minus the most recent value for each Prod_ID.

End result should look like this;

Capture 2.PNG

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Thanks in Advance

 

1 ACCEPTED SOLUTION

Hi @Anonymous 

You may try to create a measure like below:

Measure =
VAR Recent_date =
    CALCULATE ( MAX ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[Prod_ID] ) )
RETURN
    CALCULATE (
        SUM ( 'Table'[tValue] ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[Prod_ID] ), 'Table'[Date] = Recent_date )
    )
        - CALCULATE ( SUM ( 'Table'[tValue] ) )

Regards,

Community Support Team _ Cherie Chen
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

3 REPLIES 3
v-cherch-msft
Employee
Employee

Hi @Anonymous 

You may create a calculated column with below formula:

Column =
VAR Recent_date =
    CALCULATE ( MAX ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[Prod_ID] ) )
RETURN
    CALCULATE (
        SUM ( 'Table'[tValue] ),
        FILTER ( 'Table', 'Table'[Date] = Recent_date )
    ) - 'Table'[tValue]

Regards,

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

Hi @v-cherch-msft ,

 

Thanks for your reply, it's great but something is lacking.

My table has more than 2000 rows with some Prod_ID having the same latest dates.

What the formula does is for those products, it will sum all their tValues whereas I need it to calculate for each Distinct Prod_ID.

Thanks

Hi @Anonymous 

You may try to create a measure like below:

Measure =
VAR Recent_date =
    CALCULATE ( MAX ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[Prod_ID] ) )
RETURN
    CALCULATE (
        SUM ( 'Table'[tValue] ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[Prod_ID] ), 'Table'[Date] = Recent_date )
    )
        - CALCULATE ( SUM ( 'Table'[tValue] ) )

Regards,

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

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.