Forum Discussion

MRoth's avatar
MRoth
Icon for Helper I rankHelper I
10 months ago
Solved

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 DateForecasted Isoweek

Forecasted Value

01.01.2025Wk 01

1000

01.01.2025Wk 02

1000

01.01.2025Wk 03

1000

01.01.2025Wk 04

1000

01.01.2025Wk 05

1000

01.01.2025Wk 06

1000

01.01.2025Wk 07

1000

01.01.2025Wk 08

1000

01.01.2025Wk 09

1000

 ...and so on....

 

01.02.2025Wk 06

1100

01.02.2025Wk 07

1100

01.02.2025Wk 08

1100

01.02.2025Wk 09

1100

01.02.2025Wk 10

1100

 ...and so on...

 

01.03.2025WK 10

900

01.03.2025WK 11

900

01.03.2025Wk 12

900

01.03.2025Wk 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 0101.01.20251000
WK 0201.01.20251000
WK 0301.01.20251000
WK 0401.01.20251000
WK 0501.01.20251000
WK 0601.02.20251100
Wk 0701.02.20251100
Wk 0801.02.20251100
Wk 0901.02.20251100
Wk 1001.03.2025900
Wk 1101.03.2025900
Wk 1201.03.2025900
Wk 1301.03.2025900

 

What I would like to display as well, is a summary of Forecasted Values per Forecasted date, looking like this:

 

Forecast creation dateSum of relevant forecasted Values
01.01.20255000 (5x1000 for weeks 01-05)
01.02.20254400 (4x1100 for weeks 06-09)
01.03.20253600 (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:

 
VAR _Offset = NumRangeParameter[Parameter Value]

VAR _ForecastedWeekOffset =
    CALCULATE (
        MAX ( 'Calendar'[Week Start Date] ),
        ALLSELECTED ( 'Calendar'[Week #] ),
        'Calendar'[RelativeWeek]
            = SELECTEDVALUE ( 'Calendar'[RelativeWeek] ) - _Offset
    )

VAR _ForecastDate =
    CALCULATE (
        MAX ( 'FactTable'[Forecast_date]),
        'Dim Forecasts'[Frequency] = "Monthly",
       'FactTable'[Forecast_date] < _ForecastedWeekOffset
    )
 
RETURN
    _ForecastDate

 


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

  • 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's avatar
      MRoth
      Icon for Helper I rankHelper 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's avatar
        TomMartens
        Icon for Super User rankSuper 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

  • 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's avatar
      MRoth
      Icon for Helper I rankHelper 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's avatar
        TomMartens
        Icon for Super User rankSuper 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

  • 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's avatar
      MRoth
      Icon for Helper I rankHelper 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 months

      The result I am hoping to get would be a visual that looks like this.

      Forecast VersionForecasted ValueActual (for the same period)Variance
      2025F140303730-300
      2025F244463120-1326
      2025F345804130-450

       

       

       

       

       

       

      • Anonymous's avatar
        Anonymous
        Not 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

  • Anonymous's avatar
    Anonymous
    Not 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.