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

Get Fabric certified for FREE! Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Calculate difference between forecast (constant) and monthly values

Hi There, 

I have two tables; one contains the forecast values and the other contains values that increases with time (monthly). I want to subtract the maximum value for each record from the forecast values. How do I do this in DAX? The table is linked by the location number (unique ID). The forecast values are constant for each location.

Sample data below for the forecast and varing data.

Location numberForecast value
01500
02325
03460
04300
05250
Location numberDateValue
01Jan 202265
01Feb 2022100
02Apr 202220
03May 2022100
04Dec 202150

 

Example the difference for location 01 in Jan 2022 is 500 - 65 = 435. In Feb 2022 it's 400. I want this for all location numbers. I need this to information in my report to know how much of the forecast is remaining. 

Also, how do I sort my legend in ascending order? See below

jbuaba_0-1657742847273.png

 

Any help will be greatly appreciated.

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

You can try this measure,

diff = 
var _forecast= MAXX(FILTER(forecast,forecast[Location number]=MAX('Table'[Location number])),[Forecast value])
return _forecast-MAX('Table'[Value])

vxiaotang_0-1658139374758.png

if you need calculated column, try this,

Column = 
var _forecast= MAXX(FILTER(forecast,forecast[Location number]=EARLIER('Table'[Location number])),[Forecast value])
return _forecast-'Table'[Value]

vxiaotang_1-1658139472413.png

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

You can try this measure,

diff = 
var _forecast= MAXX(FILTER(forecast,forecast[Location number]=MAX('Table'[Location number])),[Forecast value])
return _forecast-MAX('Table'[Value])

vxiaotang_0-1658139374758.png

if you need calculated column, try this,

Column = 
var _forecast= MAXX(FILTER(forecast,forecast[Location number]=EARLIER('Table'[Location number])),[Forecast value])
return _forecast-'Table'[Value]

vxiaotang_1-1658139472413.png

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

@v-xiaotang thanks for the response. 

This method works however I have a little issue. Some of the location number have alphanumeric IDs. Is there a way to go around this?

Hi @Anonymous 

If you use my measure, please make sure that the columns in the blue box are of the same type, either numeric or textual

vxiaotang_0-1658913851232.png

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

I got an error when I tried the formula.

jbuaba_0-1658327717173.png

 

amitchandak
Super User
Super User

@Anonymous , Make sure both tables are joined with the common location table

 

Sum(Table[Forecast Value]) - Sum(Table2[Value])

Should work

 

or

 

sumx(Values('Date'[Month Year]), calculate(Sum(Table[Forecast Value]) - Sum(Table2[Value]) ) )

 

best it to have crossjoin with distinct monthstart date and join with date table

 

new Table= crossjoin([Table], distinct('Date'[Month Start Date]) )

 

 

again the first measure will work

 

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
Anonymous
Not applicable

@amitchandak thanks for the response.

 

I tried both methods but I got the same difference value for each location number which is not what I want. 

 

Helpful resources

Announcements
Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

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