cancel
Showing results for
Did you mean:
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

Expected outcome

1 ACCEPTED SOLUTION
Solution Specialist

Var _maxWeekNum = max(weeknum)

return

Calculate(

countrows(table),

filter(

all(table),

table[weeknum] = _maxWeekNum - 1

)

)

2 REPLIES 2
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))

Learn Power BI - Full Course with Dec-2022, with new DAX functions like Window, Index, Offset !!
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Formatted Profit and Loss Statement with empty lines
Solution Specialist

Var _maxWeekNum = max(weeknum)

return

Calculate(

countrows(table),

filter(

all(table),

table[weeknum] = _maxWeekNum - 1

)

)

Announcements

#### 2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

#### Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

#### 2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.

Top Solution Authors
Top Kudoed Authors