Building a rolling 31-day sales total with DATESBETWEEN in DAX
You have a Power BI model that contains two tables named Sales and Date. The Sales table relates to the Date table by using a many-to-one relationship. The Sales table contains the following columns: • Date • Product • SalesAmount You need to create a DAX measure for a rolling 31-day sales total that will return the total sales amount for a selected date and the previous 30 days. Which DAX expression should you use?
Community Votes
68% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
DATESBETWEEN(Date[Date], MAX(Date[Date])-30, MAX(Date[Date])) constructs the exact 31-day window ending at the selected date — the inclusive bounds on both ends are what make it 31 days rather than 30.
A Sales table relates to a Date table many-to-one, and a measure must return the total sales amount for a selected date plus the previous 30 days, so the filter expression must span exactly 31 consecutive dates.
Substituting DATEADD for a rolling window — DATEADD(Date[Date], -30, DAY) shifts the date set 30 days back (a single matching day, not a span), which is a sum over one day, not 31.
Community Discussion (12 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
DATESBETWEEN returns a contiguous date range with inclusive endpoints. MAX('Date'[Date]) in the measure's filter context is the selected date, so bounding the range from that date minus 30 days up to that date yields exactly 31 calendar days. CALCULATE then sums SalesAmount over that window, giving the rolling 31-day total the question defines as the selected date plus the previous 30 days.Why the Other Options Are Wrong
DATEADD(Date[Date], -30, DAY) (A) time-shifts the current date selection 30 days into the past, producing the single day 30 days earlier — a one-day sum, not a 31-day window. DATESMTD (C) accumulates month-to-date, which resets on the first of each month and has nothing to do with a rolling window. The DISTINCTCOUNT comparison (D) is not even a valid filter-table expression for CALCULATE; it evaluates to a boolean rather than a table of dates.Community Comment Notes
The most-endorsed comment explains that DATESBETWEEN creates the continuous range from the selected date back 30 days, which is exactly the 31-day requirement. Another commenter points out DATEADD merely shifts the selection, echoing the standard trap this question sets.Official Reference
Related Analysis
Practice All PL-300 Questions
Access 116 questions with complete answers and detailed explanations.
View Full PL-300 Practice Test →