Forum Discussion
Running Monthly Total Calculation or Filter
- 7 months ago
Hi E_Rye
Create a Date table( please check this post - https://community.fabric.microsoft.com/t5/Desktop/Creating-Date-Tables/m-p/553980) then provide relationship based on date column from Date table to your Main table
Create a measure
Active IDs =
CALCULATE(COUNTROWS(Episodes),FILTER(Episodes,Episodes[Episode Start Date <=MAX(Date[MonthEnd] )&&(
ISBLANK( Episodes[Delivery Date])
|| Episodes[Delivery Date]>=MIN(Date[MonthStart]))))Cumulative Active IDs =CALCULATE([Active IDs],
FILTER(ALL(Date[Date]),Date[Date]<=MAX( Date[Date])))
Hii E_Rye
In your data, an ID has a "Life Cycle" that starts at EpisodeStartDate and ends at DeliveryDate (or EpisodeEndDate). A standard running total often ignores the end date, causing IDs to stay in the count forever.
The Solution: The "Active ID" Pattern
Step 1: Set up a Disconnected Date Table
For dynamic filtering to work across a 24-month trend, your X-axis should come from a separate Calendar table that is not directly linked to your Episodes dates. This allows the measure to compare the "Month being viewed" against the "Dates in the row."
Step 2: Create the "Active ID" Logic
Create a measure that determines if an ID is active during a given month. Use the logic you described: EpisodeStartDate must be on or before the end of the month, and the ID must not have been "Delivered" before the start of that month.
Active ID Count =
VAR _ReportMonthStart = MAX('Calendar'[Date])
VAR _ReportMonthEnd = EOMONTH(_ReportMonthStart, 0)
RETURN
CALCULATE(
DISTINCTCOUNT(Episodes[ID]),
KEEPFILTERS(
Episodes[EpisodeStartDate] <= _ReportMonthEnd &&
(ISBLANK(Episodes[DeliveryDate]) || Episodes[DeliveryDate] >= _ReportMonthStart)
)
)
Step 3: Create the Running Total
Now, wrap that "Active" logic into a running total calculation. This will iterate through all months up to the one currently being viewed in your chart.
Running Monthly Total =
VAR _MaxDate = MAX('Calendar'[Date])
RETURN
CALCULATE(
[Active ID Count],
FILTER(
ALLSELECTED('Calendar'),
'Calendar'[Date] <= _MaxDate
)
)
Alternative: Using a Visual-Level Filter
If you want to keep your existing simple count measure, you can create a "Flag" measure:
- Create a measure: FilterFlag = IF([Active ID Count] > 0, 1, 0).
- Drag this into the Filters on this visual pane for your chart.
- Set the filter to "is 1".
If this solution worked for you, please Mark as Solution! It helps others in the community find this answer more easily. Cheers!
Hello AshokKunwar,
My semantic model already included a Date table not directly linked to the Episodes table, with a calculated column for Reporting Month = STARTOFMONTH('Date'[Date]).
I made one minor change to your logic for 'Active ID Count' to get the correct 'Running Monthly Total':
Thank you very much!
- AshokKunwar7 months agoContinued Contributor
Hii E_Rye
If this solution worked for you, please Mark as Solution! It helps others in the community find this answer more easily. Cheers!