Your algorithm is basically OK, except that, with multiple names, you can:
- Group by Name
- Create full date list for each Name
- Join the sub tables
- Do the housekeeping (sorting; replacing null with weekend, etc
Creating the datelist for each Name, within the Group function, cannot be done within the UI, but must be done in the Advanced Editor.
M Code
let
Source = Excel.CurrentWorkbook(){[Name="Table5"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{<!-- -->{"Name", type text}, {"Date", type date}, {"Schedule", type text}}),
//Group by Name
//Then create Table of dates for each subgroup
#"Grouped Rows" = Table.Group(#"Changed Type", {"Name"}, {
{"All", each _, type table [Name=nullable text, Date=nullable date, Schedule=nullable text]},
{"All Dates", each Table.FromList(
List.Dates(List.Min([Date]),
Duration.TotalDays(List.Max([Date])-List.Min([Date]))+1,
#duration(1,0,0,0)),Splitter.SplitByNothing(),{"allDates"})}
}),
//Join the two tables with a RightOuter join,
//Then "fill down" the missing names in the Name column
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "mergedDates",
each Table.FillDown(
Table.Join([All],"Date",[All Dates],"allDates",JoinKind.RightOuter),{"Name"})),
//Housekeeping
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Name", "All", "All Dates"}),
#"Expanded mergedDates" = Table.ExpandTableColumn(#"Removed Columns", "mergedDates",
{"Name", "Schedule", "allDates"}, {"Name", "Schedule", "allDates"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded mergedDates",{
{"allDates", type date}, {"Name", type text}, {"Schedule", type text}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{<!-- -->{"allDates", "Date"}}),
#"Sorted Rows" = Table.Sort(#"Renamed Columns",{<!-- -->{"Name", Order.Ascending}, {"Date", Order.Ascending}}),
#"Reordered Columns" = Table.ReorderColumns(#"Sorted Rows",{"Name", "Date", "Schedule"}),
#"Replaced Value" = Table.ReplaceValue(#"Reordered Columns",null,"Weekend",Replacer.ReplaceValue,{"Schedule"})
in
#"Replaced Value"