Forum Discussion

t-dahen's avatar
t-dahen
Icon for Microsoft Employee rankMicrosoft Employee
6 years ago
Solved

Categorical Rolling Average

Hello,   I have a table of the form:   Name | Category | Date | Sales   -It should be noted that there is a N:1 relationship between a Name and a Category (The same Name will have the same Cate...
  • stevedep's avatar
    stevedep
    6 years ago

    t-dahen ,
    ah missed that summarization of the sales per day needs to be done first. Adjusted! output is now as expected:

    Adjusted code:

     

    _2_Measure_RunningAverageNameCategorySales = 
    var _CTfilter = DATESINPERIOD('Date'[Date]; MIN('Date'[Date]);-7;DAY)
    var _CT = CALCULATETABLE(SUMMARIZE('Table';'Table'[Name];'Date'[Date];"sales"; CALCULATE(SUM('Table'[Sales]))) ;_CTfilter;ALLEXCEPT('Table';'Table'[Name];'Table'[Category]))
    return
    IF(NOT(ISBLANK(MIN('Table'[Sales])));
    AVERAGEX(_CT;[sales]);
    BLANK())
    _1_Measure_AverageOfAverageRunningSalesinCat = 
    var _sumtbl = CALCULATETABLE(SUMMARIZE('Table';'Table'[Name];'Date'[Date];'Table'[Category]; "runningsales"; [_2_Measure_RunningAverageNameCategorySales]);ALLEXCEPT('Table';'Date';'Table'[Category]))
    return
        AVERAGEX(_sumtbl; [runningsales])

     

    New file available here

    Hope we got it now?

    Kind regards, Steve.