Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Good morning guys,
I am struggling with a DAX. I am trying to build a line chart that should contain 5 lines for 5 different years (From 2017 to 2022) and one line that should be the Average of previous 5 years excluding 2022. What I am trying to do is to have a cumulative sum for every year so that I will have 5 different dax already filtered by year and in the X axis I can put months or quarters.
I am using this code for the cumulative sum :
Solved! Go to Solution.
Hi, @Danimonti91
You can try the following methods.
Column:
Year = YEAR([Date])
Month = MONTH([Date])
Cumulative sum =
CALCULATE (
SUM ( 'Table'[Sales] ),
FILTER (
'Table',
[Year] = EARLIER ( 'Table'[Year] )
&& [Month] <= EARLIER ( 'Table'[Month] )
)
)
Average =
CALCULATE (
AVERAGE ( 'Table'[Sales] ),
FILTER ( 'Table', [Year] = EARLIER ( 'Table'[Year] ) )
)
Result:
Is this the result you expect?
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, @Danimonti91
Can you simplify your data and provide some sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures. I look forward to your response.
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for the reply, imagine to have a table similar to the one below (I just put dummy data for an example). From this table I want to have a line chart, showing Sales for every year (Cumulative) and on the X axis I want the months or quarters. Additionally I also want the average of last years. So the chart in this case needs to have 2019 Cumulative, 2020 Cumulative, 2021 Cumulative, 2022 Cumulative and AVG from 2019 to 2021 with Months or Quarters on the X axis.
Thanks a lot in advance
Date | Sales |
1/1/2019 | 15 |
10/2/2019 | 7 |
22/3/2019 | 98 |
29/10/2019 | 14 |
1/1/2020 | 1 |
7/4/2020 | 34 |
8/10/2020 | 57 |
18/12/2020 | 2 |
3/2/2021 | 35 |
8/4/2021 | 23 |
10/8/2021 | 45 |
29/11/2021 | 67 |
7/2/2022 | 21 |
11/7/2022 | 45 |
18/10/2022 | 22 |
29/10/2022 | 98 |
Hi, @Danimonti91
You can try the following methods.
Column:
Year = YEAR([Date])
Month = MONTH([Date])
Cumulative sum =
CALCULATE (
SUM ( 'Table'[Sales] ),
FILTER (
'Table',
[Year] = EARLIER ( 'Table'[Year] )
&& [Month] <= EARLIER ( 'Table'[Month] )
)
)
Average =
CALCULATE (
AVERAGE ( 'Table'[Sales] ),
FILTER ( 'Table', [Year] = EARLIER ( 'Table'[Year] ) )
)
Result:
Is this the result you expect?
Best Regards,
Community Support Team _Charlotte
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@Danimonti91 , you can try YTD with date table, Date in visual should also come from date table
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Why Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5b...
Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s
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.
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
12 | |
10 | |
6 |