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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

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
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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