Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
I want to create a cumulative sum in Power BI for the last two years, based on a filter selection. The fact table has a 'Year' column linked to the 'Year' field in the calendar table, which is also used for filtering.
Cumulative Sales Last 2 Years =
VAR MaxYear = CALCULATE(
MAX(Calendar[Year]),
ALLSELECTED(Calendar)
)
VAR MinYear = MaxYear - 1
RETURN
CALCULATE(
[Total Sales],
FILTER(
ALL(Calendar),
Calendar[Year] >= MinYear &&
Calendar[Year] <= MaxYear &&
Calendar[Date] <= MAX(Calendar[Date])
)
)
However, it doesn't cumulate my sum.
Any idea how to change/improve my measure? Thank you
Solved! Go to Solution.
Hi @MCacc
Can you please try the below DAX ?
Hi @MCacc
I'm wondering why your fact table is linked to calendar on the year and not the date column and if they're linked on year, what is the use of adding Calendar[Date] <= MAX(Calendar[Date]) to your measure?
That aside, you can instead use DATESINPERIOD
Last 2 years =
CALCULATE (
SUM ( factTable[Value] ),
DATESINPERIOD ( CalendarTable[Date], MAX ( CalendarTable[Date] ), -2, YEAR ),
REMOVEFILTERS ( CalendarTable )
)
Hi @MCacc
I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.
Thank you.
Hi @MCacc
I wanted to check if you had the opportunity to review the information provided by @danextian and @mdaatifraza5556 . Please feel free to contact us if you have any further questions. If their response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.
Hi @MCacc
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you.
Hi @MCacc
I'm wondering why your fact table is linked to calendar on the year and not the date column and if they're linked on year, what is the use of adding Calendar[Date] <= MAX(Calendar[Date]) to your measure?
That aside, you can instead use DATESINPERIOD
Last 2 years =
CALCULATE (
SUM ( factTable[Value] ),
DATESINPERIOD ( CalendarTable[Date], MAX ( CalendarTable[Date] ), -2, YEAR ),
REMOVEFILTERS ( CalendarTable )
)
Hi @MCacc
Can you please try the below DAX ?
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 48 | |
| 45 | |
| 41 | |
| 19 | |
| 18 |
| User | Count |
|---|---|
| 69 | |
| 68 | |
| 33 | |
| 33 | |
| 31 |