Forum Discussion
Calculate the difference between two weeks
What a community!
I've had a little problem with my DAX formula, I'm trying to compare two weeks and see the difference that there was from one to the other, but when using the selectedvalue(DATE)-2 formula, it doesn't show any value, someone has any idea why this happens or how it could compare 2 weeks based on a filter of a slicer
Thank you so much in advance!
Best regards!
2 Replies
- amitchandakSuper User
Syndicate_Admin , 2 week from date selected ?
one of the ways is with date table
2 weeks behind sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-14,DAY)))
With Week rank column in Date
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format
Last 2 weeks = CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-2 && 'Date'[Week Rank]<=max('Date'[Week Rank])))
Last 2 weeks before 2= CALCULATE(sum('order'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-4 && 'Date'[Week Rank]<=max('Date'[Week Rank])-3))
More on the week and date table
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
https://www.youtube.com/watch?v=pnAesWxYgJ8 - v-janeyg-msftCommunity Support
Hi, Syndicate_Admin
Is your problem solved? Have you tried the formula suggested above?
According to your description, why you use selectedvalue()-2, It's not equal to two weeks. And the screenshot is not clear, it's hard to see the problem. So can you share some sample data and your desired result? Then we can modify the measure for you soon.
Best Regards
Janey Guo
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.