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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
Fraizerrrrr
Frequent Visitor

undefined

How to add a custom column for StartDate on power query but it's like this. Because on the source there is only the month column.

Fraizerrrrr_0-1713330128851.pngFraizerrrrr_1-1713330145215.png

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Fraizerrrrr ,

 

Try the following code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwNFPSUXJ08vH0czUwVIrVQRczgomZY1FnjqIuFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month = _t, Line = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", Int64.Type}, {"Line", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each #date([Month],1,1), type date),
    #"Inserted End of Year" = Table.AddColumn(#"Added Custom", "End of Year", each Date.EndOfYear([Custom]), type date),
    #"Added Custom1" = Table.AddColumn(#"Inserted End of Year", "Custom.1", each {Number.From([Custom])..Number.From([End of Year])}),
    #"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom1", "Custom.1"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom.1",{{"Custom.1", type date}}),
    #"Inserted Start of Week" = Table.AddColumn(#"Changed Type1", "Start of Week", each Date.StartOfWeek([Custom.1]), type date),
    #"Inserted End of Week" = Table.AddColumn(#"Inserted Start of Week", "End of Week", each Date.EndOfWeek([Custom.1]), type date),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted End of Week",{"Month", "Custom", "End of Year", "Custom.1"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Columns"),
    #"Inserted Merged Column" = Table.AddColumn(#"Removed Duplicates", "Merged", each Text.Combine({Text.From([Start of Week], "en-GB"), Text.From([End of Week], "en-GB")}, " to "), type text)
in
    #"Inserted Merged Column"

 

This may need some adjustments based on your model.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





View solution in original post

1 REPLY 1
MFelix
Super User
Super User

Hi @Fraizerrrrr ,

 

Try the following code:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwNFPSUXJ08vH0czUwVIrVQRczgomZY1FnjqIuFgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Month = _t, Line = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Month", Int64.Type}, {"Line", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each #date([Month],1,1), type date),
    #"Inserted End of Year" = Table.AddColumn(#"Added Custom", "End of Year", each Date.EndOfYear([Custom]), type date),
    #"Added Custom1" = Table.AddColumn(#"Inserted End of Year", "Custom.1", each {Number.From([Custom])..Number.From([End of Year])}),
    #"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom1", "Custom.1"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Expanded Custom.1",{{"Custom.1", type date}}),
    #"Inserted Start of Week" = Table.AddColumn(#"Changed Type1", "Start of Week", each Date.StartOfWeek([Custom.1]), type date),
    #"Inserted End of Week" = Table.AddColumn(#"Inserted Start of Week", "End of Week", each Date.EndOfWeek([Custom.1]), type date),
    #"Removed Columns" = Table.RemoveColumns(#"Inserted End of Week",{"Month", "Custom", "End of Year", "Custom.1"}),
    #"Removed Duplicates" = Table.Distinct(#"Removed Columns"),
    #"Inserted Merged Column" = Table.AddColumn(#"Removed Duplicates", "Merged", each Text.Combine({Text.From([Start of Week], "en-GB"), Text.From([End of Week], "en-GB")}, " to "), type text)
in
    #"Inserted Merged Column"

 

This may need some adjustments based on your model.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português





Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.