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
jwi1
Post Patron
Post Patron

Convert Year, Weeknr en Day to Date

Dear Power BI user,

 

I have the following issue.

 

I have a table containing YEAR, WEEK and NAME of the DAY MO, TUE etc).

Is it possible to convert this combination to a date (for example 02-01-2019)?

 

Thanks for your reply!

 

Knipsel.JPG

1 ACCEPTED SOLUTION
BhaveshPatel
Community Champion
Community Champion

Hi @jwi1 

 

You can use the below formula in calculated column.

 

StartDate = DATE([YEAR], 1, -2) - WEEKDAY(DATE([YEAR], 1, 3)) + [WEEK] * 7
 
Based on the WeekDay Name, You can create a SWITCH(TRUE()) Logic to add days to the above formula to get the exact date .
 
Date = DATE([YEAR], 1, -2) - WEEKDAY(DATE([YEAR], 1, 3)) + [WEEK] *7
+SWITCH(TRUE(),
[DAYNAME]="MON",0,
[DAYNAME]="TUE",1,
[DAYNAME]="WED",2,
[DAYNAME]="THU",3,
[DAYNAME]="FRI",4,
[DAYNAME]="SAT",5,
[DAYNAME]="SUN",6)
 
There may be other ways as well but I found this handy.
Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.

View solution in original post

2 REPLIES 2
BhaveshPatel
Community Champion
Community Champion

Hi @jwi1 

 

You can use the below formula in calculated column.

 

StartDate = DATE([YEAR], 1, -2) - WEEKDAY(DATE([YEAR], 1, 3)) + [WEEK] * 7
 
Based on the WeekDay Name, You can create a SWITCH(TRUE()) Logic to add days to the above formula to get the exact date .
 
Date = DATE([YEAR], 1, -2) - WEEKDAY(DATE([YEAR], 1, 3)) + [WEEK] *7
+SWITCH(TRUE(),
[DAYNAME]="MON",0,
[DAYNAME]="TUE",1,
[DAYNAME]="WED",2,
[DAYNAME]="THU",3,
[DAYNAME]="FRI",4,
[DAYNAME]="SAT",5,
[DAYNAME]="SUN",6)
 
There may be other ways as well but I found this handy.
Thanks & Regards,
Bhavesh

Love the Self Service BI.
Please use the 'Mark as answer' link to mark a post that answers your question. If you find a reply helpful, please remember to give Kudos.

Good day Bhavesh,

 

works perfect for me, thanks!

 

John

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.