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
rashel2002
Helper II
Helper II

From date to week number - formula doesn't work

Hi All,

 

I'm using the following formula to convert date to work-week:

Number.ToText(Date.WeekOfYear([MSP_EpmAssignmentByDay_UserView.TimeByDay]))

 

But then i get 53 as a work week, even though there is no ww53 in 2018.

How can i solve it? 

 

Thanks!

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

Hi @rashel2002,

 

AFAIK, date functions not works for datetime type, I'd like to suggest you add Date.From function into your formula to extract date value.

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Number.From(Date.WeekOfYear(Date.From([MSP_EpmAssignmentByDay_UserView.TimeByDay]))))

Full query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ3MNQ3MjA0VzA0sjIytDI0UIrVAQoDBcHiFgogMStDI6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Number.From(Date.WeekOfYear(Date.From([Date]))))
in
    #"Added Custom"

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

6 REPLIES 6
v-shex-msft
Community Support
Community Support

Hi @rashel2002,

 

AFAIK, date functions not works for datetime type, I'd like to suggest you add Date.From function into your formula to extract date value.

    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Number.From(Date.WeekOfYear(Date.From([MSP_EpmAssignmentByDay_UserView.TimeByDay]))))

Full query:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ3MNQ3MjA0VzA0sjIytDI0UIrVAQoDBcHiFgogMStDI6XYWAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type datetime}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Number.From(Date.WeekOfYear(Date.From([Date]))))
in
    #"Added Custom"

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Omega
Impactful Individual
Impactful Individual

If you still want it in M Query, check the below link: 

 

http://datacornering.com/how-to-calculate-iso-week-number-in-power-query/

 

 

Omega
Impactful Individual
Impactful Individual

Try creating a calculated column and use the below formula: 

 

Week = WEEKNUM('Calendar'[Date],21)
AlB
Super User
Super User

Hi @rashel2002

Can you share your file? Other factors might be playing a role

Hi, thanks for responding.

Unfortunately, i can't share the file because it's hold classified data.

But as you can see the formula is related only to the date column.

Here are some problematic dates-

34.PNG

@rashel2002

In these cases, you could share only the part that is not working while taking all the confidential data out. Or recreate the issue with dummy data.  

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.