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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

current vs previous week count

Hi Everyone, 
i have seen that dax doesnt have a previous week function, can someone assist in writing a measure that shows previous week counts to compare to that current week count as shown in the tables below. 

 

The first table is a representation of the actual data and the second table is the desired outcome.

 

If anyone can assist in writing such a measure I would greatly apreciate it,

Thank you 

 

Data table 

 

Screen Shot 2022-06-29 at 5.00.13 PM.png

 

Expected outcome 

Screen Shot 2022-06-29 at 5.05.23 PM.png

1 ACCEPTED SOLUTION
vapid128
Solution Specialist
Solution Specialist

Var _maxWeekNum = max(weeknum)

 

return

Calculate(

    countrows(table),

    filter(

        all(table),

        table[weeknum] = _maxWeekNum - 1

    )

)

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Anonymous , Please check the solution by @vapid128 , The solution work well within a year. Across year week need week rank column. Prefer a date table

 

new columns

Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

New measure examples
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

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
vapid128
Solution Specialist
Solution Specialist

Var _maxWeekNum = max(weeknum)

 

return

Calculate(

    countrows(table),

    filter(

        all(table),

        table[weeknum] = _maxWeekNum - 1

    )

)

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.