The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
Hi there,
I have sales data line items for the last 3 years that looks like the below example, and I would need some help with analyzing this data:
____Period____| | ____Product____| | ____Customer____| | ____Volume____| |
Apr 2019 | Product 1 | Customer A | 100 |
May 2019 | Product 1 | Customer A | 150 |
Jun 2019 | Product 1 | Customer A | 170 |
Jul 2019 | Product 1 | Customer A | 160 |
Aug 2019 | Product 1 | Customer A | 170 |
Apr 2020 | Product 1 | Customer A | 110 |
May 2020 | Product 1 | Customer A | 160 |
Jun 2020 | Product 1 | Customer A | 180 |
Jul 2020 | Product 1 | Customer A | 170 |
My questions are the following:
Thanks,
kukszi
Solved! Go to Solution.
Hi,
You may download my PBI file from here.
Hope this helps.
Hi @kukszi
I build a table like yours to have a test.
I build measure to achieve your goals.
Year-to-date volume this year =
VAR _Selected = SELECTEDVALUE(Calender[Date].[MonthNo])
VAR _MAXMon =
MAXX (
FILTER ( ALL ( 'Table' ), 'Table'[__Period____|].[Year] = YEAR ( TODAY () ) ),
'Table'[__Period____|].[MonthNo]
)
RETURN
CALCULATE (
SUM ( 'Table'[____Volume____|] ),
FILTER (
ALL ( 'Table' ),
'Table'[__Period____|].[Year] = YEAR ( TODAY () )
&& 'Table'[__Period____|].[MonthNo] < _MAXMon
&& 'Table'[__Period____|].[MonthNo] >= _Selected
)
)
Year-to-date volume last year =
VAR _Selected = SELECTEDVALUE(Calender[Date].[MonthNo])
VAR _MAXMon =
MAXX (
FILTER ( ALL ( 'Table' ), 'Table'[__Period____|].[Year] = YEAR ( TODAY () ) ),
'Table'[__Period____|].[MonthNo]
)
RETURN
CALCULATE (
SUM ( 'Table'[____Volume____|] ),
FILTER (
ALL ( 'Table' ),
'Table'[__Period____|].[Year]
= YEAR ( TODAY () ) - 1
&& 'Table'[__Period____|].[MonthNo] < _MAXMon
&& 'Table'[__Period____|].[MonthNo] >= _Selected
)
)
When My latest value is in Nov 2020,Result:
Default:
Select July:
2.
Rolling 3 months last year =
VAR _selectedmonth =
SELECTEDVALUE ( Calender[Date].[MonthNo] )
VAR _a =
CALCULATE (
SUM ( 'Table'[____Volume____|] ),
FILTER (
ALL ( 'Table' ),
'Table'[__Period____|].[Year]
= YEAR ( TODAY () ) - 1
&& 'Table'[__Period____|].[MonthNo] <= _selectedmonth
&& 'Table'[__Period____|].[MonthNo] >= _selectedmonth - 2
)
)
VAR _b =
CALCULATE (
SUM ( 'Table'[____Volume____|] ),
FILTER (
ALL ( 'Table' ),
'Table'[__Period____|].[Year]
= YEAR ( TODAY () ) - 2
&& 'Table'[__Period____|].[MonthNo] <= 12
&& 'Table'[__Period____|].[MonthNo] > 12 - 3 + _selectedmonth
)
)
RETURN
IF ( _selectedmonth <= 2, _a + _b, _a )
Rolling 3 months this year =
VAR _selectedmonth =
SELECTEDVALUE ( Calender[Date].[MonthNo] )
VAR _a =
CALCULATE (
SUM ( 'Table'[____Volume____|] ),
FILTER (
ALL ( 'Table' ),
'Table'[__Period____|].[Year] = YEAR ( TODAY () )
&& 'Table'[__Period____|].[MonthNo] <= _selectedmonth
&& 'Table'[__Period____|].[MonthNo] >= _selectedmonth - 2
)
)
VAR _b =
CALCULATE (
SUM ( 'Table'[____Volume____|] ),
FILTER (
ALL ( 'Table' ),
'Table'[__Period____|].[Year]
= YEAR ( TODAY () ) - 1
&& 'Table'[__Period____|].[MonthNo] <= 12
&& 'Table'[__Period____|].[MonthNo] > 12 - 3 + _selectedmonth
)
)
RETURN
IF ( _selectedmonth <= 2, _a + _b, _a )
Result:
July:
February:
You can download the pbix file from this link: Analyzing Sales Data line items
Best Regards,
Rico Zhou
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@kukszi , find a calendar of your choice -
YTD can take year-end date. Your QTR is will work with time intelligence
Last QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD(dateadd('Date'[Date],-1,QUARTER)))
Last complete QTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESQTD( ENDOFQUARTER(dateadd('Date'[Date],-1,QUARTER))))
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
This year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR('Date'[Date]),"12/31"))
Last year Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
Last to last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-2,Year),"12/31"))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
rolling
Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-12,MONTH))
Rolling 12 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date ],MAX(Sales[Sales Date]),-12,MONTH))
Rolling 3= CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],staroffmonth(Sales[Sales Date]),3,MONTH))
Rolling 3 till last month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],-1,month)),-3,MONTH))
Rolling 3 till last 2 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],-2,month)),-3,MONTH))
Rolling 3 till last 1 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],-1,month)),-3,MONTH))
Rolling 12 till last month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],-1,month)),-13,MONTH))
Rolling 3 till last 3 month = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(dateadd(Sales[Sales Date],-3,month)),-3,MONTH))
refer for more deatils
Power BI — YTD Questions — Time Intelligence 1–5
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
Power BI — QTD Questions — Time Intelligence 2–5
https://medium.com/@amitchandak.1978/power-bi-qtd-questions-time-intelligence-2-5-d842063da839
Power BI — MTD Questions — Time Intelligence 3–5
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
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 :
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-Y...
Appreciate your Kudos.
Hi,
You may download my PBI file from here.
Hope this helps.
Hey @kukszi ,
start by reading this article, it contains almost everything one needs to know about date-related calculations:
https://www.daxpatterns.com/time-patterns/
Regards,
Tom
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
105 | |
77 | |
74 | |
43 | |
37 |
User | Count |
---|---|
156 | |
109 | |
64 | |
60 | |
55 |