Forum Discussion

shinney's avatar
shinney
Helper I
4 years ago
Solved

Creating a moving average for count data ... but counting up a string column

Hello, I'm trying to create a 7 day moving average for the count of activities for each date (with Activity as the legend). I tried using the solution from this youtube tutorial video and other for...
  • AlexisOlson's avatar
    4 years ago

    Can't you just use COUNT inside of CALCULATE?

     

    Note that you can't use DATESBETWEEN unless you have a proper date dimension table set up, so you might have to use a different approach like this:

    SMA (7 day) =
    VAR CurrDate = MAX ( ActivityLogs[RetrieveDate] )
    VAR Days =
        CALCULATETABLE (
            VALUES ( ActivityLogs[RetrieveDate] ),
            ActivityLogs[RetrieveDate] <= CurrDate,
            ActivityLogs[RetrieveDate] > CurrDate - 7
        )
    RETURN
        AVERAGEX ( Days, CALCULATE ( COUNT ( ActivityLogs[Activity] ) ) )