Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

How to get rolling Wow values from the tall format data set

ItemWeekDriverScoreResp
1551D0698
1551D16.87189
1551D26.6763
1551D35.370
1552D06.92182
1552D17.24133
1552D24.5749
1552D36.2570
3551D07.8196
3551D17.3277
3551D24.97105
3551D35.07161
3552D05.31112
3552D111.370
3552D25.8342
3552D35.55133
4551D04.470
4551D15.0491
4551D28.27469
4551D33.170
4552D03.8649
4552D11535
4552D28.71133
4552D36.2149
7551D08.63119
7551D110.897
7551D24.5749
7551D310.6935
7552D0698
7552D16.87189
7552D26.6763
7552D35.370

 

Hi everyone,

I want  to calculate the WoW values of the driver at item level.

The values should be in a crosstab as below:

 

itemD0WoWD1WoWD2WoWD3WoW
19.1 8.76 8.1 9.4 
39.3 9.04 8.8 9.6 
49.4 9.18 9.15 9.7 
79.6 9.46 9.85 10.2 

 

If I select week 552 from the filter, then column D0..D3 in table 2 should show the weighted sum of score and responses and the WoW columns should show the weighted sum of week 551.

The challenge here is that if I select week 553 and 554, then I am expecting the WoW column to show the weighted mean of 551 and 552. My data is for 52 weeks. Similarly, selecting 3 consecutive weeks should give me the weighted mean of previous 3 weeks corresponding to the item and driver(D0..D3) and so on.

 

Can somebody please help me in this.

Anonymous PowBi parry2k jdbuchanan71 Greg_Deckler Cmcmahan 

  • Cmcmahan's avatar
    Cmcmahan
    7 years ago

    Ahh, now THIS makes sense.  So assuming you have a measure for the current timeframe [Weighted Mean] like this:

    Weighted Mean = SUMX('Table', [Score] * [Resp]) / SUM('Table'[Resp])

    The basic form of the DAX for a single week's WoW value would be:

    WoW Mean = [Weighted Mean] - CALCULATE( [Weighted Mean], FILTER( ALL('Table'[Week]), 'Table'[Week] = SELECTEDVALUE('Table'[Week])-1))

    Since you just want the difference between the current [Weighted Mean] and the [Weighted Mean] with a different set of weeks, you can do that with CALCULATE syntax to change the context for part of the measure. 

     

    However, you've gone a step further and added the requirement that if there are multiple weeks available via filter/slicer, then it should use the same number of previous weeks.  Still doable, we just need to get trickier in how we select the previous timeframe.

    WoW Mean (Multiweek) =
    // VAR numWeeks = DISTINCTCOUNT('Table'[Week]) // Selected weeks may not necessarily be continuous, or there may be a week with no data
    VAR numWeeks =  // Better formula for figuring out the timespan, though will still give weird results if you skip a week in slicer (e.g. Week 5,6,8 will compare data from weeks 5,6, and 8 to data from weeks 1-4)
        MAX ( 'Table'[Week] ) - MIN ( 'Table'[Week] ) + 1
    RETURN
        [Weighted Mean]
            - CALCULATE (
                [Weighted Mean],
                FILTER (
                    ALL ( 'Table'[Week] ),
                    'Table'[Week]
                        IN GENERATESERIES ( MIN ( 'Table'[Week] ) - numWeeks, MIN ( 'Table'[Week] ) - 1 )
                )
            )

    I've attached a .pbix that I used.  I added random [Score] data for weeks 53/54, but kept [Resp] the same due to laziness.

    Note that there are many ways to do this filter instead of using IN GENERATESERIES style syntax. 

    My first thought was to use IN ADDCOLUMNS(VALUES('Table'[Week]), "Prev Week", 'Table'[Week]-numWeeks)) style syntax, but I think I GENERATESERIES is an easier/clearer way to do it. This version also had the same issue of handling weeks with no data/filtered out data poorly.

    You could also use 'Table'[Week] >= MIN('Table'[Week])-numWeeks && 'Table'[Week] < MIN('Table'[Week]) style syntax, which may be easier to update, but (I think) is harder to read.   

     

    The point is to get that FILTER statement working for the previous time period's data. Once you do that to change the context properly, the rest should fall into place.

7 Replies

  • v-juanli-msft's avatar
    v-juanli-msft
    Icon for Community Support rankCommunity Support

    Hi Anonymous 

    Could you tell how to calculate the column D0..D3 in table 2 which should show the weighted sum of score and responses If I select week 552 from the filter?

     

    Best Regards
    Maggie

     

    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • Anonymous's avatar
      Anonymous
      Not applicable

      hi v-juanli-msft,

       

      Thanks for replying

      The method to calculate weighted mean is through a DAX query.

      The query is: SUMX(table, score*responses)/sum(response).

       

      This is the way to calculate D0..D3 for each item and the D0-WoW..D3-Wow is also caluclated the same way, just for the previous weeks.

       

      Is this what you were asking?

       

      Thanks

      • Cmcmahan's avatar
        Cmcmahan
        Icon for Resident Rockstar rankResident Rockstar

        I honestly have no idea where to even start so we can talk using a shared dictionary.  The data you shared is VERY helpful as a starting point, but I can't seem to replicate the 2nd table you shared that shows your current results.  I have no idea how you get to a value of 9.1 for Item 1, D0.  Or any of the other numbers in that table using the data provided. 

         

        In addition, I have no idea what a "WoW Value" is, or how to calculate it.   And that's before we add in the fact that you want a rolling WoW Value.  You seem to be wanting some sort of weighted average, but how do you determine the weight?  You say that you want WoW for previous weeks, but how many previous weeks? Should D0-WoW have the same value as D0, but for the previous week or something?

         

        I've attached the .pbix file I've played with to try and replicate your results, so you can see where I've gotten stuck.  Hopefully if you can explain what I'm missing, we can get you your WoW value.