Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

Creating a Date Table with only months

Hi all,

 

I'm trying to created a date table, where each row is equal to one month, like:

 

January 2023

February 2022

March 2022

 

I've tried a number of methods for this but I can't seem to figure it out. For example, CALANDERAUTO() gives me a row for each day, rather than a row for each month as per below:

 

 

Any help would be greatlly appreciated!

 

Thanks

  • Anonymous's avatar
    Anonymous
    3 years ago

    Hi Anonymous 

    You can refer to the following example.

    Create a new table

    Table = var a=ADDCOLUMNS(CALENDAR(DATE(2022,1,1),DATE(2023,1,1)),"Month Year",FORMAT([Date],"yyyy mmmm"))
    return SUMMARIZE(a,[Month Year])

     

    Then change the data type to date, and the format to "mmmm yyyy"

     

    Best Regards!

    Yolo Zhu

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

4 Replies

  • hi Anonymous 

    try to add a column like this:

    MonthYear = FORMAT([Date], "MMMM YYYY")
    • FreemanZ's avatar
      FreemanZ
      Icon for Super User rankSuper User

      hi Anonymous 

      or you wanna create a table from scratch, like this:

      DateTable = 
      ADDCOLUMNS(
          CALENDAR(DATE(2022,12,30), DATE(2023,1,1)),
          "MonthYear", FORMAT([Date], "MMMM YYYY"),
          "MonYear", FORMAT([Date], "MMM YYYY")
      )

       

  • Hi,

    You can create a blank query and paste this code to generate desired results.

    Please change the range as per your requirement.

    ----------------------------------

    let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDRQio0FAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [StartDate = _t]),
    #"Changed column type" = Table.TransformColumnTypes(Source, {{"StartDate", type date}}),
    #"Added custom" = Table.AddColumn(#"Changed column type", "EndDate", each "12/31/2025"),
    #"Changed column type 1" = Table.TransformColumnTypes(#"Added custom", {{"EndDate", type date}}),
    #"Added custom 1" = Table.AddColumn(#"Changed column type 1", "Date", each {Number.From([StartDate])..Number.From([EndDate])}),
    #"Expanded Date" = Table.ExpandListColumn(#"Added custom 1", "Date"),
    #"Changed column type 2" = Table.TransformColumnTypes(#"Expanded Date", {{"Date", type date}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed column type 2",{"StartDate", "EndDate"}),
    #"Calculated Start of Month" = Table.TransformColumns(#"Removed Columns",{{"Date", Date.StartOfMonth, type date}}),
    #"Removed Duplicates" = Table.Distinct(#"Calculated Start of Month")
    in
    #"Removed Duplicates"

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous 

    You can refer to the following example.

    Create a new table

    Table = var a=ADDCOLUMNS(CALENDAR(DATE(2022,1,1),DATE(2023,1,1)),"Month Year",FORMAT([Date],"yyyy mmmm"))
    return SUMMARIZE(a,[Month Year])

     

    Then change the data type to date, and the format to "mmmm yyyy"

     

    Best Regards!

    Yolo Zhu

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