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
noorkhan
Regular Visitor

Date problem

I have data in which year, month number and week number and day number of week is mentioned in separate column. how can i combine all these column to get date. 

 

Thanks

1 ACCEPTED SOLUTION
Anonymous
Not applicable

So your data looks like this, except the Date column?

 

OfTheHair_0-1659618592094.png

 

Is this data your Date table or part of your Facts table?

 

My quick and dirty solution would be to either merge your data with a Date Table that does contain dates, joining on Year, MonthNumber and Weeknummer. Or, alternatively, create a Date Table from scratch.

 

Here's the M-code for a Date Table that automatically generates dates for a period of 6 years centered on the current year.

let
    Bron = {Int64.From(Date.StartOfYear(Date.AddYears(Date.From(DateTime.LocalNow()), -3)))..Int64.From(Date.EndOfYear(Date.AddYears(Date.From(DateTime.LocalNow()),3)))},
    #"Geconverteerd naar tabel" = Table.FromList(Bron, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Type gewijzigd" = Table.TransformColumnTypes(#"Geconverteerd naar tabel",{{"Column1", type date}}),
    #"Namen van kolommen gewijzigd" = Table.RenameColumns(#"Type gewijzigd",{{"Column1", "Date"}}),
    #"Aangepaste kolom toegevoegd" = Table.AddColumn(#"Namen van kolommen gewijzigd", "Year", each Date.Year([Date])),
    #"Aangepaste kolom toegevoegd1" = Table.AddColumn(#"Aangepaste kolom toegevoegd", "MonthNumber", each Date.Month([Date])),
    #"Aangepaste kolom toegevoegd2" = Table.AddColumn(#"Aangepaste kolom toegevoegd1", "WeekNummer", each Date.DayOfWeek([Date])),
    #"Type gewijzigd1" = Table.TransformColumnTypes(#"Aangepaste kolom toegevoegd2",{{"Date", type date}, {"Year", Int64.Type}, {"MonthNumber", Int64.Type}, {"WeekNummer", Int64.Type}})
in
    #"Type gewijzigd1"

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @noorkhan ,

 

Try to add a custom column like

= Number.ToText([Year])&"-"&Number.ToText([MonthNumber])&"-"&Number.ToText(([WeekNumber]-1)*7+[day number])

ShundaSteph_0-1660123753739.png

You can change the type to date.

ShundaSteph_1-1660123781256.png

 

 

Best Regards,

ShundaSteph

 

Anonymous
Not applicable

So your data looks like this, except the Date column?

 

OfTheHair_0-1659618592094.png

 

Is this data your Date table or part of your Facts table?

 

My quick and dirty solution would be to either merge your data with a Date Table that does contain dates, joining on Year, MonthNumber and Weeknummer. Or, alternatively, create a Date Table from scratch.

 

Here's the M-code for a Date Table that automatically generates dates for a period of 6 years centered on the current year.

let
    Bron = {Int64.From(Date.StartOfYear(Date.AddYears(Date.From(DateTime.LocalNow()), -3)))..Int64.From(Date.EndOfYear(Date.AddYears(Date.From(DateTime.LocalNow()),3)))},
    #"Geconverteerd naar tabel" = Table.FromList(Bron, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Type gewijzigd" = Table.TransformColumnTypes(#"Geconverteerd naar tabel",{{"Column1", type date}}),
    #"Namen van kolommen gewijzigd" = Table.RenameColumns(#"Type gewijzigd",{{"Column1", "Date"}}),
    #"Aangepaste kolom toegevoegd" = Table.AddColumn(#"Namen van kolommen gewijzigd", "Year", each Date.Year([Date])),
    #"Aangepaste kolom toegevoegd1" = Table.AddColumn(#"Aangepaste kolom toegevoegd", "MonthNumber", each Date.Month([Date])),
    #"Aangepaste kolom toegevoegd2" = Table.AddColumn(#"Aangepaste kolom toegevoegd1", "WeekNummer", each Date.DayOfWeek([Date])),
    #"Type gewijzigd1" = Table.TransformColumnTypes(#"Aangepaste kolom toegevoegd2",{{"Date", type date}, {"Year", Int64.Type}, {"MonthNumber", Int64.Type}, {"WeekNummer", Int64.Type}})
in
    #"Type gewijzigd1"
SpartaBI
Community Champion
Community Champion

@noorkhan you don't have the day in the month maybe? :))

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.