Forum Discussion
How to get average across all dates using rolling average?
Based on your requirements, here's how to fix your measure to properly calculate averages across all dates when no date filter is applied, while maintaining the rolling 33-day average when dates are selected.
Percent Total direct deposit accounts v3 = VAR SelectedDates = IF( ISFILTERED(Dates[Date]), VALUES(Dates[Date]), // Use selected dates ALL(Dates[Date]) // Use all dates when no filter ) VAR AvgDirectDeposit = AVERAGEX( SelectedDates, [RollingAverageDirectDepositCount33Days] ) VAR AvgCheckingAccounts = AVERAGEX( SelectedDates, [RollingAverageCheckingAccountsCount33Days] ) RETURN DIVIDE( AvgDirectDeposit, AvgCheckingAccounts, 0 // Return 0 if denominator is zero )
Update your rolling average measures to handle the "no date selected" scenario
RollingAverageDirectDepositCount33Days = VAR ReferenceDate = IF( ISFILTERED(Dates[Date]), MAX(Dates[Date]), // Use max selected date when filtered TODAY() // Use today when no date filter ) RETURN CALCULATE( SUM(VW_DIRECT_DEPOSIT_V10[TOTAL_DIRECT_DEPOSIT_AMOUNT]), VW_DIRECT_DEPOSIT_V10[DIRECT_DEPOSIT_YN] = "Yes", DATESINPERIOD(Dates[Date], ReferenceDate, -33, DAY) )
RollingAverageCheckingAccountsCount33Days = VAR ReferenceDate = IF( ISFILTERED(Dates[Date]), MAX(Dates[Date]), // Use max selected date when filtered TODAY() // Use today when no date filter ) RETURN CALCULATE( DISTINCTCOUNT(VW_DIRECT_DEPOSIT_V10[ACCTNBR]), DATESINPERIOD(Dates[Date], ReferenceDate, -33, DAY) )
the individual measures were working for total direct deposit accounts and total checking accounts. What is your measure helping it do?
- Elena_Kalina1 year agoSolution Sage
The issue you're facing is that when no dates are selected in the slicer, your measure isn't properly calculating the average across all dates - it's just showing the value for the most recent date. The main problem is in how the rolling averages work when no date filter is applied. Your current formula tries to average the results, but the rolling average measures themselves are still only looking at the max date's 33-day window.
The solution does three key things:
It modifies the rolling average calculations so they use TODAY() as the reference date when no specific dates are selected, instead of defaulting to the maximum date. This ensures we're always looking at a proper 33-day window.
It properly averages the daily ratios across either:
The selected dates (when a date filter is applied)
All available dates (when no date filter is applied)
It uses DIVIDE() to safely handle cases where there might be zero checking accounts.
The main improvement is that now, when the dates are not selected instead of showing only the last value of the day, in fact it calculates the average value of all daily ratios, where the value of each day itself is a 33-day average.
This gives you the true overall average you're looking for, while still maintaining the rolling average behavior when specific dates are selected.
The solution fixes the script “without selected dates” to show the correct average, and not just the last meaning. Perhaps I did not quite understand what exactly you are looking for.
- PowerUser20001 year agoHelper I
I understand now thank you. Am I calculating the 33 day average correctly? When I look at my numbers compared to the normal month by month basis some months are now quite a bit more than the standard start of month till end of month. I guess I don't quite understand how 33 day average works.
- Elena_Kalina1 year agoSolution Sage
The differences you're observing between your 33-day rolling average and monthly averages make complete sense when we consider how these calculations work:
Continuous vs. Fixed Periods: A 33-day average updates daily and isn't tied to calendar months, while monthly averages use fixed start/end dates.
Cross-Month Inclusion: Your June average, for instance, contains data from late May, creating different comparison points.
Smoothing Effect: The longer window naturally smooths out daily fluctuations more than monthly averages.
The Seasonal Factor You Should Consider
We should also account for potential seasonality in your time patterns. While I don't know your exact data, many financial datasets show monthly patterns - often peaking at period beginnings/ends.
Here's why this matters: Your 33-day window captures two peak moments - the end of one month and start of another. When these high-value periods combine in a single average, the result naturally appears inflated compared to looking at months individually.
- Elena_Kalina1 year agoSolution Sage
try these measures
RollingAverageDirectDepositCount33Days TEST = VAR ReferenceDate = IF( ISFILTERED(Dates[Date]), MAX(Dates[Date]), // Use max selected date when filtered TODAY() // Use current date when no filter ) RETURN CALCULATE( SUM(VW_DIRECT_DEPOSIT_V10[TOTAL_DIRECT_DEPOSIT_AMOUNT]), VW_DIRECT_DEPOSIT_V10[DIRECT_DEPOSIT_YN] = "Yes", DATESINPERIOD(Dates[Date], ReferenceDate, -33, DAY) )
RollingAverageCheckingAccountsCount33Days TEST = VAR ReferenceDate = IF( ISFILTERED(Dates[Date]), MAX(Dates[Date]), // Use max selected date when filtered TODAY() // Use current date when no filter ) RETURN CALCULATE( DISTINCTCOUNT(VW_DIRECT_DEPOSIT_V10[ACCTNBR]), DATESINPERIOD(Dates[Date], ReferenceDate, -33, DAY) )
Percent Total direct deposit accounts v3 TEST = VAR HasDateFilter = ISFILTERED(Dates[Date]) VAR Ratio = DIVIDE( [RollingAverageDirectDepositCount33Days TEST], [RollingAverageCheckingAccountsCount33Days TEST], 0 // Return 0 if denominator is zero ) RETURN IF( HasDateFilter, // When dates are filtered (including monthly grouping) AVERAGEX( VALUES(Dates[Date]), // Works with monthly grouping Ratio ), // When no dates are filtered AVERAGEX( ALLSELECTED(Dates[Date]), DIVIDE( [RollingAverageDirectDepositCount33Days TEST], [RollingAverageCheckingAccountsCount33Days TEST], 0 ) ) )
- PowerUser20001 year agoHelper I
Thank you, but I'm looking for help in terms of these measures:
RollingAverageCheckingAccountsCount33Days =CALCULATE(DISTINCTCOUNT(VW_DIRECT_DEPOSIT_V10[ACCTNBR]),DATESINPERIOD(Dates[Date], MAX(Dates[Date]), -33, DAY))
Does this work when grouped by months?- Anonymous1 year agoNot applicable
Great question, I recently worked with a similar DAX measure and wanted to share a few insights that might help clarify things.
RollingAverageCheckingAccountsCount33Days = CALCULATE(DISTINCTCOUNT(VW_DIRECT_DEPOSIT_V10[ACCTNBR]),DATESINPERIOD(Dates[Date], MAX(Dates[Date]), -33, DAY))
This measure works perfectly when you're analyzing data at the daily level. It gives you the distinct count of account numbers over the past 33 days, based on the current date in context. However, when you try to group this by months, it behaves a bit differently.
Because when grouped by month, MAX(Dates[Date]) picks the last day of that month, and your rolling logic applies based only on that single date not across all days in the month. So essentially, you're just seeing the 33-day count ending on the last day of each month, not a true rolling average over the month. To get a more accurate monthly picture, here's what I did is first, i kept the rolling logic per day by using bellow measure.Rolling33DayDistinctCount = CALCULATE(DISTINCTCOUNT(VW_DIRECT_DEPOSIT_V10[ACCTNBR]),DATESINPERIOD(Dates[Date], MAX(Dates[Date]), -33, DAY))
Then, i wrapped that inside an average so that when grouping by month, it averages the daily values.
MonthlyAvg_Rolling33DayDistinctCount = AVERAGEX(VALUES(Dates[Date]), [Rolling33DayDistinctCount])
This approach gives you a much more accurate monthly number by calculating the 33-day distinct count for each day and then averaging those values across the month.
If this response helps, consider marking it as “Accept as solution” and giving a “kudos” to assist other community members.
Regards,
Akhil.