Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
Jon07
Helper I
Helper I

Cumulative sum by week number year-over-year

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! 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

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/

View solution in original post

5 REPLIES 5
amitchandak
Super User
Super User

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/

Jon07
Helper I
Helper I

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?

 

Greg_Deckler
Super User
Super User

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...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Mariusz
Community Champion
Community Champion

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] )
)

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.