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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
RobRayborn
Helper III
Helper III

Power Query, rollup Sat and Sun to Friday.

I have a report where orders that are taken on a Saturday and/or Sunday need to rollup or be combined with the orders from the previous Friday in each column that has order amounts.

So if an order was put in on Nov. 5th {Saturday} or Nov. 6th {Sunday} they would need to be added to the amount in Nov. 4th {Friday}.

I have a column that identifies each day by the Date (11/1/2022, 11/2/2022......), then 8 columns that have order data for each day.

This report is updated each day and at the end of the month should only show Weekdays, with the Friday for each week having the data from the next Sat and Sun included.

Assistance in figuring out the M Code for this would be very appreciated. 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @RobRayborn 

 

This is my solution. Hope it is helpful. 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc/BDcAgDAPAXfJGAocCYRbE/mtQVbJ59HsC21nLgIzsxd2S1Wo7feSkCFIlQa8e0qQ0Siuk/qchUlSQ+iBNFVJQVKhZ0Pqpn9B8qBPaP26eDugaAp1w43RCvLYP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Amount", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "DayOfWeek", each Date.DayOfWeek([Date],Day.Monday)),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "WeekOfYear", each Date.WeekOfYear([Date],Day.Monday)),
    #"Replaced Value" = Table.ReplaceValue(#"Added Custom1",5,4,Replacer.ReplaceValue,{"DayOfWeek"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",6,4,Replacer.ReplaceValue,{"DayOfWeek"}),
    #"Added Custom2" = Table.AddColumn(#"Replaced Value1", "WeekDayKey", each [WeekOfYear]*10+[DayOfWeek]),
    #"Grouped Rows" = Table.Group(#"Added Custom2", {"WeekDayKey"}, {{"New Date", each List.Min([Date]), type nullable date}, {"New Amount", each List.Sum([Amount]), type nullable number}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"New Date", "New Amount"})
in
    #"Removed Other Columns"

vjingzhang_0-1669616090905.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

 

View solution in original post

1 REPLY 1
v-jingzhang
Community Support
Community Support

Hi @RobRayborn 

 

This is my solution. Hope it is helpful. 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Zc/BDcAgDAPAXfJGAocCYRbE/mtQVbJ59HsC21nLgIzsxd2S1Wo7feSkCFIlQa8e0qQ0Siuk/qchUlSQ+iBNFVJQVKhZ0Pqpn9B8qBPaP26eDugaAp1w43RCvLYP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, Amount = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"Amount", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "DayOfWeek", each Date.DayOfWeek([Date],Day.Monday)),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "WeekOfYear", each Date.WeekOfYear([Date],Day.Monday)),
    #"Replaced Value" = Table.ReplaceValue(#"Added Custom1",5,4,Replacer.ReplaceValue,{"DayOfWeek"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value",6,4,Replacer.ReplaceValue,{"DayOfWeek"}),
    #"Added Custom2" = Table.AddColumn(#"Replaced Value1", "WeekDayKey", each [WeekOfYear]*10+[DayOfWeek]),
    #"Grouped Rows" = Table.Group(#"Added Custom2", {"WeekDayKey"}, {{"New Date", each List.Min([Date]), type nullable date}, {"New Amount", each List.Sum([Amount]), type nullable number}}),
    #"Removed Other Columns" = Table.SelectColumns(#"Grouped Rows",{"New Date", "New Amount"})
in
    #"Removed Other Columns"

vjingzhang_0-1669616090905.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors