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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
kozlevchar
Resolver I
Resolver I

Subtracting values in a column by prior Date filtered by another column

Hello PBI Community,

 

I have what I thought might be a common problem.  

 

I need to subtract the cost column by the prior date filtered by the Material number.  Here's the table:

DateMaterial Cost 
3/1/2022 11223344         10,000
3/1/2022 12345678         30,000
3/1/2022 23456789         25,000
3/1/2022 34567891         50,000
3/1/2022 45678912         35,000
4/1/2022 11223344         20,000
4/1/2022 12345678         35,000
4/1/2022 23456789         20,000
4/1/2022 34567891         60,000
4/1/2022 45678912         25,000

 

For example, the difference in cost for Material 11223344 would be +10,000 (20,000 - 10,000).

 

I am able to create separate Measures for current cost (using MAX function) and previous cost (using PREVIOUSMONTH) then subtracting the measures but was hoping to create a measure where I can subtract any month w/o having to create separate measures.

Any help would be much appreciated!

 

Thank you,

 

John 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Untitled.png

 

Cost Diff measure: = 
VAR _currentcost =
    SUM ( Data[Cost] )
VAR _previousmonthcost =
    CALCULATE ( SUM ( Data[Cost] ), PREVIOUSMONTH ( 'Calendar'[Date] ) )
RETURN
    IF (
        _currentcost = BLANK ()
            || _previousmonthcost = BLANK (),
        " ",
        _currentcost - _previousmonthcost
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

 

Untitled.png

 

Cost Diff measure: = 
VAR _currentcost =
    SUM ( Data[Cost] )
VAR _previousmonthcost =
    CALCULATE ( SUM ( Data[Cost] ), PREVIOUSMONTH ( 'Calendar'[Date] ) )
RETURN
    IF (
        _currentcost = BLANK ()
            || _previousmonthcost = BLANK (),
        " ",
        _currentcost - _previousmonthcost
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Thanks so much.  Very appreciated!

 

John

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.