cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
tatenda24
Frequent Visitor

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

@tatenda24 , 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-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8



Power BI Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!
Want To Learn Power BI | Beginners !! Advance Concepts !! Power BI For Tableau User !!
vapid128
Solution Specialist
Solution Specialist

Var _maxWeekNum = max(weeknum)

 

return

Calculate(

    countrows(table),

    filter(

        all(table),

        table[weeknum] = _maxWeekNum - 1

    )

)

Helpful resources

Announcements
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors