Forum Discussion
Measure for running total between two dates
- 6 years ago
I initially solved this with a brute force method in SQL, creating a new table with a row for each account for each month live and running a countrows over this. While this worked and allowed interactivity the table itself was massive and would grow by millions of rows each year.
Have just cracked this using DAX:
1. Add a date table to the model, for this example just the date and month name was needed.
2. Create a active relationship from Live Date to the Date column in the date table
3. Create an inactive relationship from Close Date to the Date column in the date table
4. Add the following measure:
Running Live = VAR RunningPlacedTotal = CALCULATE ( COUNTA ( 'Base Data'[Live Month] ), FILTER ( ALL ( 'Dates Base'[MonthName] ), ISONORAFTER ( 'Dates Base'[MonthName], MAX ( 'Dates Base'[MonthName] ), DESC ) ) ) VAR RunningCloseTotal = CALCULATE ( COUNTA ( 'Base Data'[Close Month] ), USERELATIONSHIP ( 'Base Data'[Close Date], 'Dates Base'[DateID] ), FILTER ( ALL ( 'Dates Base'[MonthName] ), ISONORAFTER ( 'Dates Base'[MonthName], MAX ( 'Dates Base'[MonthName] ), DESC ) ) ) RETURN RunningPlacedTotal - RunningCloseTotal5. Add graph with measure to values, and the date table month to the axis.
6. Add a visual level relative date filter to match your needs.
Hope this helps!
I initially solved this with a brute force method in SQL, creating a new table with a row for each account for each month live and running a countrows over this. While this worked and allowed interactivity the table itself was massive and would grow by millions of rows each year.
Have just cracked this using DAX:
1. Add a date table to the model, for this example just the date and month name was needed.
2. Create a active relationship from Live Date to the Date column in the date table
3. Create an inactive relationship from Close Date to the Date column in the date table
4. Add the following measure:
Running Live =
VAR RunningPlacedTotal =
CALCULATE (
COUNTA ( 'Base Data'[Live Month] ),
FILTER (
ALL ( 'Dates Base'[MonthName] ),
ISONORAFTER ( 'Dates Base'[MonthName], MAX ( 'Dates Base'[MonthName] ), DESC )
)
)
VAR RunningCloseTotal =
CALCULATE (
COUNTA ( 'Base Data'[Close Month] ),
USERELATIONSHIP ( 'Base Data'[Close Date], 'Dates Base'[DateID] ),
FILTER (
ALL ( 'Dates Base'[MonthName] ),
ISONORAFTER ( 'Dates Base'[MonthName], MAX ( 'Dates Base'[MonthName] ), DESC )
)
)
RETURN RunningPlacedTotal - RunningCloseTotal5. Add graph with measure to values, and the date table month to the axis.
6. Add a visual level relative date filter to match your needs.
Hope this helps!