Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
mruizprieto17
Frequent Visitor

Accumulated sum of the previous year

Hello, I Try to calculate the sum accumulate. My fuction is:

 

accum tons current year = CALCULATE (
SUM('table'[tm] ),
FILTER(ALL(table),
'table'[fch_ini_bunk]<= max(table[fch_ini_bunk])
&& table[dim_anio_periodo] = max(table[dim_anio_periodo])
))
When you represent this in plot line, the sentence work well. 
mruizprieto17_0-1640691715652.png

However, mi client told me that he want only the max year and previous year. For example, if yoy select 2021, in the graph only select 2021 and 2020. If you select 2020, the graph represents 2020 and 2019.

 

For this reason, I Try to calculate to meassure of dax. The fisrt calculate sum accumulate for year selected. The second calculates accumulated sum for prevouos year. But, I don't know how to filter this dax per year.

 
table for analisis:
 
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@mruizprieto17 , with help from date table and time intelligence try  measure like

 

YTD Sales = CALCULATE(SUM('table'[tm] ),DATESYTD('Date'[Date],"12/31"))

 

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

 

To 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 :radacad sqlbi My Video Series Appreciate your Kudos.

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

@mruizprieto17 , with help from date table and time intelligence try  measure like

 

YTD Sales = CALCULATE(SUM('table'[tm] ),DATESYTD('Date'[Date],"12/31"))

 

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

 

To 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 :radacad sqlbi My Video Series Appreciate your Kudos.

Good option to calculate sum. But I need to calculate accumulate sum. It posible to follow this step, but i will think. In this moment, This road has:

YTD Sales = CALCULATE(SUM('table'[tm] ),DATESYTD('Date'[Date],"12/31"))

YTD Sales LY = CALCULATE(SUM('table'[tm] ),DATESYTD('Date'[Date],"12/31"))

I try to calculate accumulate sum of YTD Sales and YTD Sales LY

@mruizprieto17 , No YTD should do. Year as a legend, month no as axis, and YTD measure as values 

I donn't understand this comment. 

If represents YTD Sales in measure, month in axis, and year as a legeng, the graph is:

 

mruizprieto17_0-1640707932853.png

But the result is not accumulate. And when you select one yeaar, the resto of year dissapear.

mruizprieto17_1-1640708271900.png

 

the example with this link has the solution:

https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a

 

You can download YTD file and create the meassure YTD and LYTD. 

mruizprieto17
Frequent Visitor

one piece of data:

dim_anio_periodo dim_mes_periodo dim_dia_periodo fch_ini_bunk tm

2019 1 1 01/01/2019 3:05 5000
2019 1 2 02/01/2019 21:06 28000
2019 1 3 03/01/2019 0:50 218400
2019 1 4 04/01/2019 0:30 120000
2019 1 5 05/01/2019 18:55 33000
2019 2 2 02/02/2019 11:15 50000
2019 2 3 03/02/2019 18:45 71000
2019 2 4 04/02/2019 8:00 150000
2019 3 19 19/03/2019 0:35 200000
2019 4 9 09/04/2019 15:10 50000
2019 4 10 10/04/2019 18:35 30000
2019 4 14 14/04/2019 21:45 222002019 1 1 01/01/2019 3:05 5000
2019 1 2 02/01/2019 21:06 28000
2019 1 3 03/01/2019 0:50 218400
2019 1 4 04/01/2019 0:30 120000
2019 1 5 05/01/2019 18:55 33000
2019 2 2 02/02/2019 11:15 50000
2019 2 3 03/02/2019 18:45 71000
2019 2 4 04/02/2019 8:00 150000
2019 3 19 19/03/2019 0:35 200000
2019 4 9 09/04/2019 15:10 50000
2019 4 10 10/04/2019 18:35 30000
2019 4 14 14/04/2019 21:45 22200

2019 4 15 15/04/2019 0:01 46540
2019 5 31 31/05/2019 21:05 22000
2019 6 1 01/06/2019 9:35 30000
2019 6 2 02/06/2019 0:10 2000
2019 6 14 14/06/2019 3:40 50000
2019 6 15 15/06/2019 0:01 80000
2019 7 31 31/07/2019 8:30 78700
2019 8 3 03/08/2019 2:15 7000
2019 8 7 07/08/2019 2:15 42000
2019 9 8 08/09/2019 9:00 12000
2019 9 15 15/09/2019 21:20 80000
2019 10 8 08/10/2019 10:35 3000
2019 10 9 09/10/2019 0:01 138000
2019 10 11 11/10/2019 16:45 75000
2019 10 12 12/10/2019 9:30 20000
2019 10 13 13/10/2019 0:03 29700
2019 12 28 28/12/2019 1:00 40000
2019 12 30 30/12/2019 1:55 15000
2019 12 31 31/12/2019 6:07 3800
2020 1 1 01/01/2020 11:00 15000
2020 1 2 02/01/2020 9:42 170000
2020 1 3 03/01/2020 1:15 9900
2020 1 11 11/01/2020 3:00 5000
2020 2 6 06/02/2020 18:00 15000
2020 2 7 07/02/2020 7:00 10800
2020 4 9 09/04/2020 12:45 45000
2020 5 2 02/05/2020 12:00 210000
2020 12 3 03/12/2020 22:03 3200
2020 12 4 04/12/2020 0:00 130000
2021 1 12 12/01/2021 11:14 3200
2021 2 28 28/02/2021 6:05 64200
2021 3 1 01/03/2021 1:25 80000
2021 3 2 02/03/2021 11:27 3
2021 4 26 26/04/2021 20:07 2
2021 4 27 27/04/2021 2:01 103000
2021 5 27 27/05/2021 17:00 60000
2021 7 20 20/07/2021 7:41 1750
2021 9 23 23/09/2021 12:36 89800
2021 10 24 24/10/2021 11:00 147800
2021 10 24 24/10/2021 16:30 120000
2021 11 15 15/11/2021 9:40 170000
2021 11 15 15/11/2021 11:21 1839
2021 12 7 07/12/2021 16:12 1954
2021 12 21 21/12/2021 18:45 19000

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

Top Solution Authors