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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Peavey
Helper II
Helper II

DAX for date to weeknumber

I have a "Start date" that has this format: 20-jan-20 1:59:42 

I am trying to pull the weeknumber from this with DAX. 

Trying to use WEEKNUM but don't get the choice of choosing "Start date".

 

Tips?

-A-

1 ACCEPTED SOLUTION
v-lionel-msft
Community Support
Community Support

Hi @Peavey ,

 

v-lionel-msft_0-1615861628230.png

Check the data type of the [Start date] column. The WEEKNUM() function can only accept date type fields as the first parameter.

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-lionel-msft
Community Support
Community Support

Hi @Peavey ,

 

v-lionel-msft_0-1615861628230.png

Check the data type of the [Start date] column. The WEEKNUM() function can only accept date type fields as the first parameter.

 

Best regards,
Lionel Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

My tip?  Don't do it this way.

 

I assume you don't have a calendar table. You should get one of those. https://exceleratorbi.com.au/power-bi-calendar-tables/

Then split the column you have in your current table into a date column and a time column. 
join the new date column to the calendar table. 
use power query to add the weeknumber column you need into the calendar. 
use the calendar table weeknumber as needed. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
amitchandak
Super User
Super User

@Peavey , Is format is datetime?

 

Or try like

new column =

var _Date = date(year([Start date]),month([Start date]),day([Start date]))

return

weeknum(_date)

 

 

 

also check

Week Start date = 'Date'[Date]+-1*WEEKDAY('Date'[Date],2)+1
Week End date = 'Date'[Date]+ 7-1*WEEKDAY('Date'[Date],2)

 

Any Weekday Week - Start From Any day of Week
https://community.powerbi.com/t5/Community-Blog/Any-Weekday-Week-Decoding-Date-and-Calendar-2-5-Powe...

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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