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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

 

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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