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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Anonymous
Not applicable

Change YTD with Week Slicer

Hi,

 

I'd like to show the latest week sales and YTD sales, with YTD calculating from the start of the year to the selected week on a slicer.

 

I've selected week 5 on my slicer so i want YTD to show the sum of sales from WK1 to 5. I've written several measures for YTD but they all return just the sales for WK5 and not YTD to week 5:

 

test3 = CALCULATE([sales],DATESYTD(DateTable[CalendarDate],"30/03")) ... this brings back just WK5 sales
test4 = TOTALYTD([sales],DateTable[CalendarDate]) ... this brings back just WK5 sales

 

I have data for week 6 onwards so i cant simply remove the filters without data reading beyond WK5.

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , Not very clear but with week year and week number you can have it. But use a separate table

 

YTD Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Number]<=max('Date'[Week Number]) && 'Date'[Week Year]= max('Date'[Week Year])))

YTD till last Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Number]<=max('Date'[Week Number]) -1 && 'Date'[Week Year]= max('Date'[Week Year])))
LYD Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Number]=max('Date'[Week Number]) && 'Date'[Week Year]= max('Date'[Week Year])-1 ))

 

Week column need in Date table

Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1 // Monday to sunday week
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Number = WEEKNUM([Date],2)

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @amitchandak 

 

Out of interest, why didnt the 'filter(all(...)' remove the slicer filter and therefore sum a YTD for the full year and not just weeks 1 to 5?

amitchandak
Super User
Super User

@Anonymous , Not very clear but with week year and week number you can have it. But use a separate table

 

YTD Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Number]<=max('Date'[Week Number]) && 'Date'[Week Year]= max('Date'[Week Year])))

YTD till last Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Number]<=max('Date'[Week Number]) -1 && 'Date'[Week Year]= max('Date'[Week Year])))
LYD Week = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Number]=max('Date'[Week Number]) && 'Date'[Week Year]= max('Date'[Week Year])-1 ))

 

Week column need in Date table

Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1 // Monday to sunday week
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Number = WEEKNUM([Date],2)

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Thanks, this solution works perfectly!

Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!