Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
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 @Anonymous
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] )
)
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 |
|---|---|
| 51 | |
| 37 | |
| 35 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 70 | |
| 64 | |
| 39 | |
| 33 | |
| 23 |