cancel
Showing results for
Did you mean:
Helper I

## Passing two values to Weeknum function

Good morning everybody,

I hope you can help me solve the following problem:

the source table feeding my PBI report is extracted on Monday evenings from a system, and I have to calculate the new orders issued by the purchasing department in the last week. To do that, I thought of filtering the week number through the WEEKNUM function, but the WEEKNUM function starts counting from Mondays, so the instruction:

WEEKNUM(MAX([OrderDate]))

would only yield the orders issued on a single day, i.e. the Monday of the data extraction. Therefore, the agreed solution is to count the previous week orders too (8 days, but there comes the problem: how shoud I convince Dax 🙂 to pass two values to the WEEKNUM function, i.e. the last week plus the preious one ? I wrote the following filter:

WEEKNUM ( Orders[OrderDate] ) = OR ( WEEKNUM ( MAX ( Orders[OrderDate] ) ), WEEKNUM ( MAX ( Orders[OrderDate] ) )-1)

but obviously I get a message saying that Dax doesn’t support comparison between Integer values and True/False values.

What I want to obtain from my Count(OrderID), given that were 27 orders issued in week 49 and 31 orders in week 48, is 27+31 =58. Is it possible ?

I hope all the above sounds clear.

Giovanni

1 ACCEPTED SOLUTION
Super User

Have these new columns in Date Table, Week Rank is Important in Date/Week Table
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

These measures can help
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))

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

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
2 REPLIES 2
Super User

Have these new columns in Date Table, Week Rank is Important in Date/Week Table
Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)
Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

These measures can help
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))

Time Intelligence, DATESMTD, DATESQTD, DATESYTD, Week On Week, Week Till Date, Custom Period on Period,
Custom Period till date: https://youtu.be/aU2aKbnHuWs&t=145s

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
Helper I

Thank you very much for your support !

Giovanni

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.

#### Ted's Dev Camp - January 26, 2023

This session will provide guidance and teach campers the skills required to build Power BI reports that support multiple languages.

#### 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