Forum Discussion
Show running total
Hey,
I made a graph that shows the running total to the last 3 years.
Here is how I did the measure:
Measure 2 = CALCULATE( SUM(DWH_GlobalSalesLong[Line_Value_Dollars]),FILTER(ALLSELECTED(DWH_GlobalSalesLong),DWH_GlobalSalesLong[Invoice_Month]<=MAX(DWH_GlobalSalesLong[Invoice_Month]) ))Also, please see attached photo:
As you can see, each year starts with the total of the end of last year (last December).
Hi Anonymous
Create a date table
date = ADDCOLUMNS(CALENDAR(DATE(2016,1,1),DATE(2020,12,31)),"year",YEAR([Date])) add columns year-month = FORMAT([Date],"yyyymm") month = FORMAT([Date],"Mmm")Show running total for last 3 years:
Measure 3 = IF(MAX([year])>YEAR(TODAY())-3,CALCULATE(SUM(Sheet3[value]),DATESYTD('date'[Date],"12/31")))or show last 3 years' running total for each year,
for 2018, running total is from 2016-2018
for 2019, is from 2017-2019
Measure = VAR lastdate1 = LASTDATE ( 'date'[Date] ) RETURN CALCULATE ( SUM ( Sheet3[value] ), FILTER ( ALLSELECTED ( 'date' ), 'date'[year-month] <= MAX ( 'date'[year-month] ) && DATEDIFF ( 'date'[Date], lastdate1, YEAR ) < 3 && DATEDIFF ( 'date'[Date], lastdate1, YEAR ) >= 0 ) ) Measure 2 = IF(MAX([year])>YEAR(TODAY())-3,[Measure])Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
7 Replies
- Mariusz
Community Champion
Hi Anonymous
Try using DATESYTD function
= CALCULATE( SUM( InternetSales_USD[SalesAmount_USD] ), DATESYTD(DateTime[DateKey] ) )https://docs.microsoft.com/en-us/dax/datesytd-function-dax
Best Regards,
Mariusz
If this post helps, then please consider Accepting it as the solution.
Please feel free to connect with me.
LinkedIn - amitchandak
Super User
Anonymous , use time intelligence with a date table example
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Power BI — YTD Questions — Time Intelligence 1–5
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38aTo get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/
See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184
Appreciate your Kudos.- AnonymousNot applicable
amitchandak , I simply want to make a comparison of the running total of the last 3 years. Do I have to use time intelligence?
Any other simple way?
Thanks
- amitchandak
Super User
Anonymous , I think that is the simplest way. In case you do not have a date.
Check out first few mins of this video - https://www.facebook.com/watch/?v=343509629992272
- v-juanli-msft
Community Support
Hi Anonymous
Create a date table
date = ADDCOLUMNS(CALENDAR(DATE(2016,1,1),DATE(2020,12,31)),"year",YEAR([Date])) add columns year-month = FORMAT([Date],"yyyymm") month = FORMAT([Date],"Mmm")Show running total for last 3 years:
Measure 3 = IF(MAX([year])>YEAR(TODAY())-3,CALCULATE(SUM(Sheet3[value]),DATESYTD('date'[Date],"12/31")))or show last 3 years' running total for each year,
for 2018, running total is from 2016-2018
for 2019, is from 2017-2019
Measure = VAR lastdate1 = LASTDATE ( 'date'[Date] ) RETURN CALCULATE ( SUM ( Sheet3[value] ), FILTER ( ALLSELECTED ( 'date' ), 'date'[year-month] <= MAX ( 'date'[year-month] ) && DATEDIFF ( 'date'[Date], lastdate1, YEAR ) < 3 && DATEDIFF ( 'date'[Date], lastdate1, YEAR ) >= 0 ) ) Measure 2 = IF(MAX([year])>YEAR(TODAY())-3,[Measure])Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.