Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
How can I calculate the running total within a group/ timerange, but do so across multiple years whil using the date slicer?
I'm trying to calculate a running total for amounts, but do so in a way that I can compare prior years to each other in the same trending line graph. It is not a YTD calculation, but rather a slice of time (example: March 10 - April 15) that can be determined by the user. I have found ways to do this within a single year, but not across multiple years. So I need a running total within that slice, grouped by the year.
Additionally, I have been asked to use the date sliding range slicer, becaues it is so intuitive and easy for the user. So I would have a slicer for 2020, and need to have data from 2019 and 2018 still show up. When I user Power BI's native date filters, the past years are literally filtered out.
Here is a link to the Power BI .pbix File with what I have vs. what I'm trying to do. There are a couple of text boxes in there with notes.
https://drive.google.com/open?id=1sVBNi51i4h1KV3cZhnYeIRo7byRMERfS
Thank you!
Solved! Go to Solution.
Hi @SBatHB ,
I've created this file as an example: Download PBIX
Please, check if it helps.
If you consider it as a solution, please mark it as a solution, so we can help others.
Ricardo
Hi @SBatHB,
If you want your date slicer works as a 'selector' and not directly filter on your records, please not use date field which related to fact table fields.
You can create a new table with date field as the source of slicer, then add a condition in your dax formula to compare with current date fields and select date ranges.
Measure =
VAR currDate =
MAX ( 'Fact'[Date] )
RETURN
CALCULATE (
'Fact'[Amount],
FILTER (
ALLSELECTED ( 'Fact' ),
YEAR ( 'Fact'[Date] ) = YEAR ( currDate )
&& 'Fact'[Date] <= currDate
&& 'Fact'[Date] IN ALLSELECTED ( Selector[Date] )
)
)
Regards,
Xiaoxin Sheng
Hi @SBatHB ,
I've created this file as an example: Download PBIX
Please, check if it helps.
If you consider it as a solution, please mark it as a solution, so we can help others.
Ricardo
For those lokking at this, the solution in the Power BI workbook provided by camargos88 is here:
Running Total =
VAR _dtMin = CALCULATE(MINX(Sheet1, Sheet1[Date]), ALLSELECTED())
VAR _dtMax = CALCULATE(MAXX(Sheet1, Sheet1[Date]), ALLSELECTED())
VAR _tblCross = SELECTCOLUMNS(ADDCOLUMNS(CROSSJOIN(DATESBETWEEN(Sheet1[Date], _dtMin, _dtMax), VALUES(Sheet1[Date].[Year])), "N_DATE", DATE(Sheet1[Date].[Year], MONTH(Sheet1[Date]), DAY(Sheet1[Date]))), "N_DATE", [N_DATE])
VAR _currentDate = SELECTEDVALUE(Dates[Date])
VAR _minDate = CALCULATE(MIN(Dates[Date]), FILTER(ALL(Dates), Dates[Date] in _tblCross && Dates[Date].[Year] = YEAR(_currentDate)))
RETURN SUMX(FILTER(Dates, Dates[Date] in _tblCross), CALCULATE(SUM(Sheet1[Amount]), FILTER(ALL(Sheet1[Date]), Sheet1[Date] >= _minDate && Sheet1[Date] <= MAX(Dates[Date]))))
I don't fully understand it, but it looks to use variables to
So it's essentially finding a date range, and then calculating between those. I'm not sure, but it looks like the lack of relationship between the date table and my Fact table could be important.
Thanks for providing this solution!
By using ALL or ALLEXCEPT or REMOVEFILTERS.
See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.
https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...
ALL and ALLEXCEPT were both solutions that I came across, but I must be calculating the running total incorrectly for them to properly work. Applicable in other DAX functions though; thanks!
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
105 | |
99 | |
99 | |
38 | |
37 |
User | Count |
---|---|
157 | |
121 | |
73 | |
73 | |
63 |