Forum Discussion

AlanRGroskreutz's avatar
6 years ago
Solved

DAX Moving hourly average/count

Hi all, I'm having a terrible time trying to get my time span filter working for a moving count.  I am working on an Air Traffic Predictor model that we'll show the occupancy of air traffic sectors....
  • TaylorClark's avatar
    6 years ago

    AlanRGroskreutz, let me know if this is what you're looking for:

     

     

    rolling entry count =
      var windowStart = SELECTEDVALUE(results[Entry 20 min Date time bin])
      var windowEnd = windowStart + TIME(0, 20, 0)
      return CALCULATE(
        COUNT(results[Entry Time]), // After we change filters, do our calculation
        FILTER( // Replace any existing filter on the [Entry 20 min Date tiem bin] column with one that looks at the period we want
          ALL(results[Entry 20 min Date time bin]), // Look through *all* values in the column, ignoring any existing filters
          [Entry 20 min Date time bin] >= windowStart && [Entry 20 min Date time bin] <= windowEnd // Keep those rows which are in our time range
      )
    )

     

     

     
    Matrix with results
     
    The key here is to use ALL to clear any groupings/filters that are applied to look at rows of your table which might be filtered out in the scope that the measure is being executed in.