Forum Discussion
Sum Values in Matrix based in another value in that matrix
Hi,
I am pretty stuck on a issue where I got almost there but can't get the last bit to work. In Excel I'd use a Sumifs and be done in 2minutes.
Scenario is Forecast Data similar to this.
Fact Table
| Forecast creation Date | Forecasted Isoweek | Forecasted Value |
| 01.01.2025 | Wk 01 | 1000 |
| 01.01.2025 | Wk 02 | 1000 |
| 01.01.2025 | Wk 03 | 1000 |
| 01.01.2025 | Wk 04 | 1000 |
| 01.01.2025 | Wk 05 | 1000 |
| 01.01.2025 | Wk 06 | 1000 |
| 01.01.2025 | Wk 07 | 1000 |
| 01.01.2025 | Wk 08 | 1000 |
| 01.01.2025 | Wk 09 | 1000 |
| ...and so on.... |
| |
| 01.02.2025 | Wk 06 | 1100 |
| 01.02.2025 | Wk 07 | 1100 |
| 01.02.2025 | Wk 08 | 1100 |
| 01.02.2025 | Wk 09 | 1100 |
| 01.02.2025 | Wk 10 | 1100 |
| ...and so on... |
| |
| 01.03.2025 | WK 10 | 900 |
| 01.03.2025 | WK 11 | 900 |
| 01.03.2025 | Wk 12 | 900 |
| 01.03.2025 | Wk 13 | 900 |
| ...and so on.... |
|
I sucessfully created a measure that tells me which forecast date and forecast value I would like to compare to. In a Matrix visual it looks like this
| Isoweek (Dimension) | Forcast creation date (Measure) | Forecasted Value (Measure) |
| WK 01 | 01.01.2025 | 1000 |
| WK 02 | 01.01.2025 | 1000 |
| WK 03 | 01.01.2025 | 1000 |
| WK 04 | 01.01.2025 | 1000 |
| WK 05 | 01.01.2025 | 1000 |
| WK 06 | 01.02.2025 | 1100 |
| Wk 07 | 01.02.2025 | 1100 |
| Wk 08 | 01.02.2025 | 1100 |
| Wk 09 | 01.02.2025 | 1100 |
| Wk 10 | 01.03.2025 | 900 |
| Wk 11 | 01.03.2025 | 900 |
| Wk 12 | 01.03.2025 | 900 |
| Wk 13 | 01.03.2025 | 900 |
What I would like to display as well, is a summary of Forecasted Values per Forecasted date, looking like this:
| Forecast creation date | Sum of relevant forecasted Values |
| 01.01.2025 | 5000 (5x1000 for weeks 01-05) |
| 01.02.2025 | 4400 (4x1100 for weeks 06-09) |
| 01.03.2025 | 3600 (4x900 for weeks 10-13) |
To make things a little more complicated, I use a numeric range parameter to offset the forecast date by 0, -1 or -2 months to measure my accuracy against various distances. My actuals are stored in a seperate fact table.
In case it's needed, the measure that curently returns the date is:
Many thanks for your help
Hey MRoth ,
have fun.I will no longer work on this, because I consider the provided information lacking, and for this reason, I'm wasting my precious spare time.
Regards,
Tom
17 Replies
- TomMartens
Super User
Hey MRoth ,
despite my last questions from a little earlier, I think this measure is doing the trick regarding the Forcasted Value:tom forecasted value = // offset value var currentOffset = SELECTEDVALUE( 'Offset'[Parameter] ) return CALCULATE( sum( 'Forecasts'[Forecasted Value] ), OFFSET( CurrentOffset * -1, SUMMARIZE(ALLSELECTED('Forecasts'), 'Dim Forecasts'[ForecastVersion], 'Forecasts'[ForcastWeek]), ORDERBY('Forecasts'[ForcastWeek]), KEEP, PARTITIONBY('Dim Forecasts'[ForecastVersion]) ) )
Please be aware that I changed the data type of Forecasts[ForecastsWeek] to "whole number"; otherwise, the ORDERBY clause in the OFFSET function will order the weeks alphabetically.At least the results look reasonable 😉
Hopefully, this helps to tackle your challenge.
Regards,
Tom- MRoth
Helper I
Hi TomMartens ,
appologies, it's been a few days until I had capacity to look at your reply.
Unfortunately not quite the result I am hoping for.
Your big table on the right shows multiple forecast versions per week, therefore your result in the left table is for Forecasted Value is the sum of all those weeks, even the ones that I didn't want to consider.
Your right table should look like this
So that the sum of ForecastedValue, per (Used)ForecastVersion only considers the weeks where that version was 'active'.
Based on my example,F1 2025 = 4026
F2 2025 = 4442
and so on...Thanks
Marius- TomMartens
Super User
Hey MRoth,
how do I know when a version is active?
How does the Offset value affect this, given the expected value for the Forecast Version of F1 2025?
Please describe the underlying rule without using DAX.
What role plays the Calendar table?
Regards,
Tom
- ajaybabuinturi
Super User
Hi MRoth,
Could you please try with below DAX function , if it is not works could you please provide some sample data of .pbix file so that I can try to provide solution.Forecasted Values by Selected Date = Var _SelectedDate = SELECTEDVALUE ( 'FactTable'[Forecast creation Date] ) RETURN CALCULATE(SUM('FactTable'[Forecasted Value]), FILTER(ALL('FactTable'), 'FactTable'[Forecast creation Date] = _SelectedDate) )Thanks,
If you found this solution helpful, please consider giving it a Like👍 and marking it as Accepted Solution✔. This helps improve visibility for others who may be encountering/facing same questions/issues.- MRoth
Helper I
Thank you for your attempt. Unfortunately this returns the sum of all forecast values related to that date, not just the ones that were returned using the measure I posted.
- TomMartens
Super User
Hey MRoth ,
please described the expected outcome based on data you provided, do not use DAX to explain what you are going achieve. But make sure that you refer to the sample data.
Regards,
Tom
- TomMartens
Super User
Hey MRoth ,
please prepare a pbix file that contains sample data but still reflects the semantic model (tables, relationships, calculated columns, and measures). Upload the pbix to OneDrive, Google Drive, or Dropbox and share the link.
I'm wondering why you mentioned the Matrix visual, as the results look like a "normal" table.
As a measure returns a scalar value, there needs to be something that provides a context for the visualization, otherwise there is only one row.
Maybe you need to rethink your current solution in a way that you have the column "Forecast Creation Date" in your calendar table, this column then provides the context.
Then the measure is using a SUMX to iterated across the facttable.
Regards,Tom
- MRoth
Helper I
Thanks TomMartens for offering your help.
I may have tried to oversimplify my scenario when I posted and it caused a loss of necessary information.
As requested, attached Pbix and my dummy source data in excel .
I mentioned a matrix as I got PBI to display the first step as intended. Please note that I used version numbers instead of dates, and the parameter shift is in weeks not monthsThe result I am hoping to get would be a visual that looks like this.
Forecast Version Forecasted Value Actual (for the same period) Variance 2025F1 4030 3730 -300 2025F2 4446 3120 -1326 2025F3 4580 4130 -450 - AnonymousNot applicable
Hi MRoth ,
You can achieve your expected summarized output by creating a DAX table or measure that groups the data by Forecast Version and aggregates the corresponding Forecasted and Actual values. Try using the SUMMARIZECOLUMNS or SUMMARIZE functions in DAX to build a summary table that calculates totals for each version and then derives the Variance as the difference between the Actual and Forecasted values. For example, you can create a new calculated table that summarizes your base data by Forecast Version, sums the forecast and actual columns, and adds a calculated variance column. This approach will give you a clean, version-level comparison like the output you shared, with one row per forecast version showing the aggregated forecast, actual, and variance.I hope this information helps. Please do let us know if you have any further queries.
Thank you
- AnonymousNot applicable
Hi MRoth
I wanted to check if you had the opportunity to review the information provided by TomMartens . Please feel free to contact us if you have any further questions.
Thank you.