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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
JL0101
Helper II
Helper II

Calculating the difference using Max Value

I have the code below that is a measure, where I want find the difference in weight based on the latest value and the previsous value however when I use the code below the coumn is blank, any help on this? Thanks 

 

 

 

a2 = 
VAR MaxRevision = MAX(Full_Rebar[Revision Number])
VAR PreviousRevision = MAX(Full_Rebar[Revision Number]) - 1
RETURN
     CALCULATE(SUM(Full_Rebar[weight_calculated_BS8666]),(Full_Rebar[Revision Number]=MaxRevision)-SUM(Full_Rebar[weight_calculated_BS8666]),(Full_Rebar[Revision Number]=PreviousRevision))

 

 

 
1 ACCEPTED SOLUTION
AnalyticsWizard
Solution Supplier
Solution Supplier

@JL0101 

 

The issue with your measure is likely due to the way you're trying to subtract the SUM functions directly within the `CALCULATE` function, which isn't valid syntax in DAX. You need to compute the sums separately and then subtract them. Here’s how you can revise your measure to correctly calculate the difference in weight between the latest revision and the previous revision:

 

Weight Difference =
VAR MaxRevision = MAX(Full_Rebar[Revision Number])
VAR PreviousRevision = MaxRevision - 1
VAR WeightCurrent = CALCULATE(
SUM(Full_Rebar[weight_calculated_BS8666]),
Full_Rebar[Revision Number] = MaxRevision
)
VAR WeightPrevious = CALCULATE(
SUM(Full_Rebar[weight_calculated_BS8666]),
Full_Rebar[Revision Number] = PreviousRevision
)
RETURN
WeightCurrent - WeightPrevious


1. MaxRevision and PreviousRevision: These variables store the maximum revision number and the previous revision number respectively.

 

2. WeightCurrent and WeightPrevious: These variables calculate the total weight for the current and previous revisions using the `CALCULATE` function, which changes the context of the calculation to match the specified revision numbers.

 

3. Return Statement: Subtracts the previous revision's weight from the current revision's weight to find the difference.

 

This measure will return the difference in weight between the two specified revisions. Make sure that both revisions exist in your dataset; if the previous revision does not exist for some entries, the measure might return blank for those cases. This approach assumes that `Revision Number` is numeric and sequential.

 

If you encounter any more blanks, verify that `Revision Number` values are correctly inputted and that there are indeed records for both the maximum and the previous revisions in your dataset.

 

If this post helps, please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍

View solution in original post

6 REPLIES 6
AnalyticsWizard
Solution Supplier
Solution Supplier

@JL0101 

 

The issue with your measure is likely due to the way you're trying to subtract the SUM functions directly within the `CALCULATE` function, which isn't valid syntax in DAX. You need to compute the sums separately and then subtract them. Here’s how you can revise your measure to correctly calculate the difference in weight between the latest revision and the previous revision:

 

Weight Difference =
VAR MaxRevision = MAX(Full_Rebar[Revision Number])
VAR PreviousRevision = MaxRevision - 1
VAR WeightCurrent = CALCULATE(
SUM(Full_Rebar[weight_calculated_BS8666]),
Full_Rebar[Revision Number] = MaxRevision
)
VAR WeightPrevious = CALCULATE(
SUM(Full_Rebar[weight_calculated_BS8666]),
Full_Rebar[Revision Number] = PreviousRevision
)
RETURN
WeightCurrent - WeightPrevious


1. MaxRevision and PreviousRevision: These variables store the maximum revision number and the previous revision number respectively.

 

2. WeightCurrent and WeightPrevious: These variables calculate the total weight for the current and previous revisions using the `CALCULATE` function, which changes the context of the calculation to match the specified revision numbers.

 

3. Return Statement: Subtracts the previous revision's weight from the current revision's weight to find the difference.

 

This measure will return the difference in weight between the two specified revisions. Make sure that both revisions exist in your dataset; if the previous revision does not exist for some entries, the measure might return blank for those cases. This approach assumes that `Revision Number` is numeric and sequential.

 

If you encounter any more blanks, verify that `Revision Number` values are correctly inputted and that there are indeed records for both the maximum and the previous revisions in your dataset.

 

If this post helps, please consider Accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudo 👍

Looks like the issue is that the previous revision is not

VAR PreviousRevision = MaxRevision - 1


Rather it is a the previous list (python term) item of 

Full_Rebar[Revision Number]


How would I get the previous list item of Full_Rebar[Revision Number]? 

I had a closer look and for some reason WeightPrevious is coming up with no values i.e. blank ?

Thank you!

amitchandak
Super User
Super User

@JL0101 , try like

 

a2 =
VAR MaxRevision = MAX(Full_Rebar[Revision Number])
VAR PreviousRevision = MAX(Full_Rebar[Revision Number]) - 1
RETURN
CALCULATE(SUM(Full_Rebar[weight_calculated_BS8666]),Full_Rebar[Revision Number]=MaxRevision)-calculate(SUM(Full_Rebar[weight_calculated_BS8666]),Full_Rebar[Revision Number]=PreviousRevision)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

I get the following error

 

A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression. This is not allowed.

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.