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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

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
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.