cancel
Showing results for
Did you mean:

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a \$100 discount. Register Now

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

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

Helper I

Thank you very much for your support !

Giovanni

Announcements

#### Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

#### Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors