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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

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.

Top Solution Authors