Forum Discussion
Current Week versus Last Week Totals as a Bar Chart
- Anonymous4 years ago
Hi Anonymous ~
I created a sample:
Please try these measures:
Current Week = var __Today = TODAY() var __WeekStartDate = __Today-WEEKDAY(__Today,1)+1 var __WeekEndDate = __WeekStartDate+6 return CALCULATE(COUNTROWS('Table'),FILTER(ALL('Table'),__WeekStartDate<='Table'[Closed] && __WeekEndDate>='Table'[Closed]))Last Week = var __Today = TODAY() var __WeekStartDate = __Today-WEEKDAY(__Today,1)-6 var __WeekEndDate = __WeekStartDate+6 return CALCULATE(COUNTROWS('Table'),FILTER(ALL('Table'),__WeekStartDate<='Table'[Closed] && __WeekEndDate>='Table'[Closed]))create a table:
create a measure:
Measure Value = SWITCH( SELECTEDVALUE('Table1'[order]), 1,[Current Week], 2,[Last Week] )Finally create a bar chart:
Hope it helps!
Best regards,
Community Support Team Gao
If this post helps, please consider Accept it as the solution to help the other members find it more quickly.
Anonymous , Create these new columns in date table
new columns
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],1)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],1)
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format
Then try measures
measures
This Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))
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
Or share data in text format as suggested by mh2587
I'm getting the following error message: