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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
msdf
Frequent Visitor

Working out week_date from a date column

Hi there 

 

Need help with adjusting the calculation for a custom column. 

 

We currently use: Date.AddDays([STRT_DTE],([Week]-1)*7), to work out the date of the following week , the "Projection Week" column. 

 

msdf_2-1723181227890.png

 

The issue now is with a new data set where there are both days and weeks mixed in the "Week" column. See "Day/Week" column below. 

It gives data at a day level for 35days (5 weeks) so WK1 is essentially week 6. 

 

What I would like to do is to bring back the date of the week just as the above formula does, for these dates. 

Hope someone can help amend the formula to get the desired result. 

TIA

 

msdf_3-1723181349244.png

 

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi,

Thanks for the concern of dufoq3 , and i want to offer some more information for user to refet to.

hello @msdf , based on your descriprion, you can create a blank query and put the following code to advanced editor in power query.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdI7DoRADATRu0yMBN1m+YQrbeYDWAhx/2ssuSutpPU8c9/DmvfZi9cxjd/30nimFk0xKK4UPxQ3ijvFg+JJUQtWNAlRQpWQJXQJYUKZkCa0GW3m90Kb0Wa0GW1Gm9FmtBltgbZAW/BnRFugLbqtsm9V9qXKvlPZVypp473e8wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Start Date" = _t, #"Day/Week" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Date", type text}, {"Day/Week", type text}}),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Start Date", type datetime}}, "en-GB"),
    #"Added Custom2" = Table.AddColumn(#"Changed Type with Locale", "Custom", each Number.FromText(Text.Select([#"Day/Week"],{"0".."9"}))),
    #"Added Custom1" = Table.AddColumn(#"Added Custom2", "Custom.1", each let 
a=Number.Mod([Custom],7),
b=if Text.Contains([#"Day/Week"],"DAY") and a=0 then Number.Round([Custom]/7) else null
in b),
    #"Filled Up" = Table.FillUp(#"Added Custom1",{"Custom.1"}),
    #"Added Custom" = Table.AddColumn(#"Filled Up", "WeekNo", each if [Custom.1]=null then List.Max(#"Filled Up"[Custom.1]) +[Custom] else [Custom.1]),
    #"Added Custom3" = Table.AddColumn(#"Added Custom", "Projection Week", each Date.AddDays([Start Date],([WeekNo]-1)*7)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom3",{"Custom", "Custom.1"})
in
    #"Removed Columns"

 

Output

 

vxinruzhumsft_0-1723431037869.png

 

 

 

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.

View solution in original post

Hi,

 

Result

dufoq3_0-1723476386770.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ldVNasNADAXgqwSvA5Y0P5K6C3RXsg4l5P7XqJ9C8K7MA2Nv9DEa+Y39fG6mu/huYv2i9iVyXJfbfbtu37dfPR467bifVdvr+j9CuY7JoVZIOdSBOrnSKESuhDW0OYe8UONQAFkCxTLKQpNDKqUaqSoTJqSqUCjbYaVC2Q4rFrW7vkssooqFTA5VLKRxqGIhZHuIRTpnkIrslKn3msoZlEdwBnmImrmuIww6GokwgBASoTN3EiEN3kmERVxJhGHPIBHiMCuxsYwaBjcbibCdKSRCIoaTCJ2NTiLUZ5IIiUhmeo8f/RAbqwRD8Br3Lrkk3sehjuAqqRPx/kuvknF+vm3VzM9nwfIkrz8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Start Date" = _t, #"Day/Week" = _t, Projection = _t, Week = _t]),
    DuplicatedColumn = Table.DuplicateColumn(Source, "Day/Week", "Day/Week2"),
    SplitColumnByCharacterTransition = Table.SplitColumn(DuplicatedColumn, "Day/Week2", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"DayWeek Text", "DayWeek Number"}),
    ChangedType = Table.TransformColumnTypes(SplitColumnByCharacterTransition,{{"DayWeek Number", Int64.Type}}),
    LastDay = Table.Max(Table.SelectRows(ChangedType, each [DayWeek Text] = "DAY"), {"DayWeek Number"})[DayWeek Number],
    StepBack = ChangedType,
    Ad_WeekNumber = Table.AddColumn(StepBack, "Week Number", each if [DayWeek Text] = "DAY" then Number.RoundUp([DayWeek Number]/7, 0) else LastDay/7 + [DayWeek Number], Int64.Type),
    RemovedColumns = Table.RemoveColumns(Ad_WeekNumber,{"DayWeek Text", "DayWeek Number"})
in
    RemovedColumns

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi,

Thanks for the concern of dufoq3 , and i want to offer some more information for user to refet to.

hello @msdf , based on your descriprion, you can create a blank query and put the following code to advanced editor in power query.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bdI7DoRADATRu0yMBN1m+YQrbeYDWAhx/2ssuSutpPU8c9/DmvfZi9cxjd/30nimFk0xKK4UPxQ3ijvFg+JJUQtWNAlRQpWQJXQJYUKZkCa0GW3m90Kb0Wa0GW1Gm9FmtBltgbZAW/BnRFugLbqtsm9V9qXKvlPZVypp473e8wc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Start Date" = _t, #"Day/Week" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Start Date", type text}, {"Day/Week", type text}}),
    #"Changed Type with Locale" = Table.TransformColumnTypes(#"Changed Type", {{"Start Date", type datetime}}, "en-GB"),
    #"Added Custom2" = Table.AddColumn(#"Changed Type with Locale", "Custom", each Number.FromText(Text.Select([#"Day/Week"],{"0".."9"}))),
    #"Added Custom1" = Table.AddColumn(#"Added Custom2", "Custom.1", each let 
a=Number.Mod([Custom],7),
b=if Text.Contains([#"Day/Week"],"DAY") and a=0 then Number.Round([Custom]/7) else null
in b),
    #"Filled Up" = Table.FillUp(#"Added Custom1",{"Custom.1"}),
    #"Added Custom" = Table.AddColumn(#"Filled Up", "WeekNo", each if [Custom.1]=null then List.Max(#"Filled Up"[Custom.1]) +[Custom] else [Custom.1]),
    #"Added Custom3" = Table.AddColumn(#"Added Custom", "Projection Week", each Date.AddDays([Start Date],([WeekNo]-1)*7)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom3",{"Custom", "Custom.1"})
in
    #"Removed Columns"

 

Output

 

vxinruzhumsft_0-1723431037869.png

 

 

 

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.

dufoq3
Super User
Super User

Hi, could you provide expected output based on 2nd screenshot?


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

msdf
Frequent Visitor

Hi @dufoq3 

 

Essentially I would like to work out Column D. Then I can work out Column E. 

Note: Days in Column B have been converted to Week number in Column D. 

msdf_0-1723430733142.png

Start DateDay/WeekProjectionWk_NumberWeek
21/07/2024 12:00:00 AMDAY1162121/07/2024
21/07/2024 12:00:00 AMDAY2156121/07/2024
21/07/2024 12:00:00 AMDAY3151121/07/2024
21/07/2024 12:00:00 AMDAY4146121/07/2024
21/07/2024 12:00:00 AMDAY5141121/07/2024
21/07/2024 12:00:00 AMDAY6137121/07/2024
21/07/2024 12:00:00 AMDAY7133121/07/2024
21/07/2024 12:00:00 AMDAY8129228/07/2024
21/07/2024 12:00:00 AMDAY9126228/07/2024
21/07/2024 12:00:00 AMDAY10123228/07/2024
21/07/2024 12:00:00 AMDAY11120228/07/2024
21/07/2024 12:00:00 AMDAY12116228/07/2024
21/07/2024 12:00:00 AMDAY13113228/07/2024
21/07/2024 12:00:00 AMDAY1411024/08/2024
21/07/2024 12:00:00 AMDAY1510634/08/2024
21/07/2024 12:00:00 AMDAY1610334/08/2024
21/07/2024 12:00:00 AMDAY1710034/08/2024
21/07/2024 12:00:00 AMDAY189734/08/2024
21/07/2024 12:00:00 AMDAY199434/08/2024
21/07/2024 12:00:00 AMDAY209134/08/2024
21/07/2024 12:00:00 AMDAY218834/08/2024
21/07/2024 12:00:00 AMDAY2285411/08/2024
21/07/2024 12:00:00 AMDAY2383411/08/2024
21/07/2024 12:00:00 AMDAY2480411/08/2024
21/07/2024 12:00:00 AMDAY2577411/08/2024
21/07/2024 12:00:00 AMDAY2674411/08/2024
21/07/2024 12:00:00 AMDAY2771411/08/2024
21/07/2024 12:00:00 AMDAY2868411/08/2024
21/07/2024 12:00:00 AMDAY2966518/08/2024
21/07/2024 12:00:00 AMDAY3063518/08/2024
21/07/2024 12:00:00 AMDAY3160518/08/2024
21/07/2024 12:00:00 AMDAY3257518/08/2024
21/07/2024 12:00:00 AMDAY3354518/08/2024
21/07/2024 12:00:00 AMDAY3499518/08/2024
21/07/2024 12:00:00 AMDAY3596518/08/2024
21/07/2024 12:00:00 AMWK196625/08/2024
21/07/2024 12:00:00 AMWK27371/09/2024
21/07/2024 12:00:00 AMWK311188/09/2024
21/07/2024 12:00:00 AMWK482915/09/2024
21/07/2024 12:00:00 AMWK51161022/09/2024
21/07/2024 12:00:00 AMWK6881129/09/2024

Hi,

 

Result

dufoq3_0-1723476386770.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("ldVNasNADAXgqwSvA5Y0P5K6C3RXsg4l5P7XqJ9C8K7MA2Nv9DEa+Y39fG6mu/huYv2i9iVyXJfbfbtu37dfPR467bifVdvr+j9CuY7JoVZIOdSBOrnSKESuhDW0OYe8UONQAFkCxTLKQpNDKqUaqSoTJqSqUCjbYaVC2Q4rFrW7vkssooqFTA5VLKRxqGIhZHuIRTpnkIrslKn3msoZlEdwBnmImrmuIww6GokwgBASoTN3EiEN3kmERVxJhGHPIBHiMCuxsYwaBjcbibCdKSRCIoaTCJ2NTiLUZ5IIiUhmeo8f/RAbqwRD8Br3Lrkk3sehjuAqqRPx/kuvknF+vm3VzM9nwfIkrz8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Start Date" = _t, #"Day/Week" = _t, Projection = _t, Week = _t]),
    DuplicatedColumn = Table.DuplicateColumn(Source, "Day/Week", "Day/Week2"),
    SplitColumnByCharacterTransition = Table.SplitColumn(DuplicatedColumn, "Day/Week2", Splitter.SplitTextByCharacterTransition((c) => not List.Contains({"0".."9"}, c), {"0".."9"}), {"DayWeek Text", "DayWeek Number"}),
    ChangedType = Table.TransformColumnTypes(SplitColumnByCharacterTransition,{{"DayWeek Number", Int64.Type}}),
    LastDay = Table.Max(Table.SelectRows(ChangedType, each [DayWeek Text] = "DAY"), {"DayWeek Number"})[DayWeek Number],
    StepBack = ChangedType,
    Ad_WeekNumber = Table.AddColumn(StepBack, "Week Number", each if [DayWeek Text] = "DAY" then Number.RoundUp([DayWeek Number]/7, 0) else LastDay/7 + [DayWeek Number], Int64.Type),
    RemovedColumns = Table.RemoveColumns(Ad_WeekNumber,{"DayWeek Text", "DayWeek Number"})
in
    RemovedColumns

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.