Forum Discussion

Jdidrik's avatar
Jdidrik
New Member
1 year ago
Solved

Problem with Running Total Sum and Weeks where input = 0

  Hi, I have problems with calculating Running sum of number of revisions in a 6 week span.  I have in total 10  engineers and I want to see the total number of revisions for rolling 6 weeks. ...
  • MarkLaf's avatar
    MarkLaf
    1 year ago

    So, the below is similar to what you were trying.

     

    Rolling6WeekTotalRev_BadEngineerFilter = 
    VAR _thisWk = MAX( Query1[Week] )
    VAR _filt = FILTER( 
        ALL( Query1[Week] ), 
        Query1[Week] > _thisWk-6 
        && Query1[Week] <= _thisWk 
    )
    RETURN
    CALCULATE( SUM( Query1[rev] ), _filt )

     

    This works as you want when Query1[Assigned Engineer] is not used in the visual's fields.

     

     

    But, it suddenly does not work correctly if we put Query1[Assigned Engineer] in the Legend, as you have highlighted in your posts.

     

     

    To see what is happening, we can do a simple test. Replace our measure with the following:

    Test = 1

     

    This is a simple constant, in any part of the visual where a value can be displayed, it will provide a 1. With this, our stacked columns with Query1[Assigned Engineer] in Legend looks like the below.

     

    It's a little clearer now what the issue is. With Query1[Assigned Engineer] in Legend, it prevents any value from calculating for ( Query1[Week], Query1[Assigned Engineer] ) pairings that do not exist in our table. With the current model, it is impossible to get the result you want.

     

    The answer is that you need to put this into a star schema. Or, at the very least, move Engineer into a separate dimension table. Below are some quick steps to do this if you are not already familiar.

     

    First, create your dimension table. Click Modeling > New Table and do something like the below:

    Engineers = ALL( Query1[Assigned Engineer] )

     

    Now, relate your new table to the original:

     

     

    Your new model should now look something like this.

     

     

    Next, in your stacked column visual, replace Query1[Assigned Engineer] with Engineers[Assigned Engineer] in the Legend. With this change, the following measure will work. Note it is almost identical except how we calculate the current week at the top.

     

    Rolling6WeekTotalRev = 
    VAR _thisWk = CALCULATE( MAX( Query1[Week] ), REMOVEFILTERS( Engineers ) )
    VAR _filt = FILTER( 
        ALL( Query1[Week] ), 
        Query1[Week] > _thisWk-6 
        && Query1[Week] <= _thisWk 
    )
    RETURN
    CALCULATE( SUM( Query1[rev] ), _filt )