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!
Sounds like you can avoid having to create a new measure!
Simply create a new chart in Power BI with the Close Month as your x axis. For your values, put in a count of "Live Month". Then to only show live accounts, filter the visual by "Close Month" to only show the January 2099 values. You should be able to recreate the two charts you have in Excel!
Hope this helps!
- TwiggyHaz6 years agoFrequent Visitor
Cheers for the reply! Have attached my results, both by just showing the 9999s and also by excluding them. Can't get the same results unless I have done somthing incorrect?
Just 9999sExcluding 9999s
- Anonymous6 years agoNot applicable
My mistake! Use "Live Month" for your x-axis, and then use count of "Live Month" for your values. This way you are counting the amount of Live Accounts were created in that month. Then place "Close Month" as a visual filter and filter to only show the 2099's, limiting the data to only show live accounts that have not been closed
Hope this works!
- TwiggyHaz6 years agoFrequent Visitor
Have updated with your suggestion and still cannot get this to work? Again unless I have made a mistake on my end?