Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I am trying to calculate a culumative sum by week number and compare it year over year in a line chart. I have week numbers on the x-axis and sum on the y-axis. I also have a dim_date table to help me with the mapping of weeknumbers, where date is the joining key between the two tables.
I used the totalYTD() function, but then I only get to choose between year-quarter-month-day in the hierarchy.
So I am wondering if either a) I can include weeknum in the date hierarchy or b) I need to use a different type of measure?
Thanks!
Solved! Go to Solution.
If you can create a date table and create your weeks there you should be able to do so.
Please refer to this file. Check the date table. I have used Rank to compare weeks but in your case, totalytd and datesytd will work with date table and week view by
https://www.dropbox.com/s/d9898a48e76wmvl/sales_analytics_weekWise.pbix?dl=0
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))
This Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((ENDOFYEAR('Date'[Date])),"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
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/
If you can create a date table and create your weeks there you should be able to do so.
Please refer to this file. Check the date table. I have used Rank to compare weeks but in your case, totalytd and datesytd will work with date table and week view by
https://www.dropbox.com/s/d9898a48e76wmvl/sales_analytics_weekWise.pbix?dl=0
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(('Date'[Date]),"12/31"))
This Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD((ENDOFYEAR('Date'[Date])),"12/31"))
Last YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(dateadd('Date'[Date],-1,Year),"12/31"))
Last YTD complete Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD(ENDOFYEAR(dateadd('Date'[Date],-1,Year)),"12/31"))
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/
Thank you for the answers.
I need to compare several years, not just last year. And neither of the answers adressed the weeknumber problem.
Since totalYTD() requires a date as a input and weeknumber is not.
But in my head I should be able to sum the amount (which is linked to a date) and categorize it by weeknumber (which is mapped to a date key in dim_date). Alas, I can't seem to work this one out.
I have no problem comparing the numbers year-over-year, if it is by month, year, quarter or day.
Did you manage to resolve this? please how did you go about with this?
Please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
See if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.
https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...
Hi @Jon07
If you need to compare week vs same week last year, you can use SAMEPERIODLASTYEAR as per below
Sales Last Year =
CALCULATE(
[Sales],
SAMEPERIODLASTYEAR( 'Calendar'[Date] )
)
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
106 | |
105 | |
79 | |
69 | |
61 |
User | Count |
---|---|
143 | |
104 | |
103 | |
82 | |
70 |