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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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