Forum Discussion
DAX Cumulative sum in date interval
I have a table that registers log access (userIds and dates). I'm counting the number of users in a period of time by doing:
Thank you! You were right about using ALLSELECTED, but your solution would still not accumulate. Here is the final solution:
users_distinctcount_acc_until_date = CALCULATE( [users_distinctcount], FILTER( ALLSELECTED(userLogTable), userLogTable[date] <= max(calendarTable[Date]) ) )
4 Replies
- amitchandak
Super User
flaviorangel , better to use date/calendar table joined with your table
CALCULATE(
[users_distinctcount],
FILTER(
ALL(Date),
Date[date] <= max(Date[Date])
)
)You can also explore the window function
Power BI Window function Rolling, Cumulative/Running Total, WTD, MTD, QTD, YTD, FYTD: https://youtu.be/nxc_IWl-tTc
- TomasAndersson
Solution Sage
Hi!
Try using ALLSELECTED() instead, while calculating min_date from inside the filter:users_distinctcount_acc_until_date = CALCULATE( [users_distinctcount], FILTER( ALLSELECTED(userLogTable), userLogTable[date] <= max(calendarTable[Date]) && userLogTable[date] >= min(calendarTable[Date]) ) )Hope this helps!
- flaviorangelNew Member
Thank you! You were right about using ALLSELECTED, but your solution would still not accumulate. Here is the final solution:
users_distinctcount_acc_until_date = CALCULATE( [users_distinctcount], FILTER( ALLSELECTED(userLogTable), userLogTable[date] <= max(calendarTable[Date]) ) )- TomasAndersson
Solution Sage
Ah, right. MIN is not needed there.
Glad you managed to get it to work!