Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Rolling average on index

Hi everyone,   I need some help on creating a rolling average. My data show the number of customers who came into stores A, B, and C, by date. My rolling average should have the following: 1. Nume...
  • mahoneypat's avatar
    6 years ago

    Please try this expression.  It gets the correct result for Stores B and C on 2/17/2020.  However, since Store A had no customers on that day, it returns blank for Store A when the date = 2/17/2020.  To get around that, you'll need to add a Date table and make a relationship to your FootTraffic[Date] column.  Then you can adapt this measure to get the VALUES of your Date[Date] column instead.

     

    Last 5 Open Days =
    VAR __maxdate =
        MAX ( FootTraffic[Date] )
    VAR __openlast5 =
        TOPN (
            5,
            CALCULATETABLE (
                VALUES ( FootTraffic[Date] ),
                FootTraffic[Open Day] = "Open",
                ALL ( FootTraffic[Date] ),
                FootTraffic[Date] >= __maxdate - 6,
                FootTraffic[Date] <= __maxdate
            ),
            FootTraffic[Date], DESC
        )
    VAR __customercount =
        SUMX ( __openlast5, CALCULATE ( SUM ( FootTraffic[Customer] ) ) )
    VAR __opendayswithcustomers =
        COUNTROWS (
            FILTER ( __openlast5, CALCULATE ( SUM ( FootTraffic[Customer] ) ) > 0 )
        )
    RETURN
        DIVIDE ( __customercount, __opendayswithcustomers )

     

    If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

    Regards,

    Pat