Power Query -- Fill down based on grouped index

gxm204

New Member
Joined
Nov 20, 2015
Messages
29
Hi all, This is in some ways a follow-up to an earlier thread. I was able to create a grouped index number to repeat at every N rows (which effectively partitions my groups), but now I am trying to figure out how to create a column where the first entry in the `Location` column of each `Group` index is used to fill a new column. This way I actually have the grouped labeled by location.

Thoughts and ideas appreciated, thank you.

1617394054327.png
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
No one really wants to rebuild your data to find a solution. Post some sample data using XL2BB. Also show a mocked up solution so we understand exactly what you are looking to do.
 
Upvote 0
Hi all, This is in some ways a follow-up to an earlier thread. I was able to create a grouped index number to repeat at every N rows (which effectively partitions my groups), but now I am trying to figure out how to create a column where the first entry in the `Location` column of each `Group` index is used to fill a new column. This way I actually have the grouped labeled by location.

Thoughts and ideas appreciated, thank you.

View attachment 35831

OK, here is the XL2bb: The Location-Fill is the mocked-up column that I am hoping to derive based on the Location and Group columns.

LocationGroupLocation-Fill (derive this column)
Mid Michigan0Mid Michigan
Clicks0Mid Michigan
Impressions0Mid Michigan
South Michigan1South Michigan
Clicks1South Michigan
Impressions1South Michigan
West Michigan2West Michigan
Clicks2West Michigan
Impressions2West Michigan
 
Upvote 0
Will this work for you:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", type text}, {"Group", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Group"}, {{"Custom", each _, type table [Location=nullable text, Group=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Locations-Fill", each [Custom]{0}[Location]),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Location"}, {"Location"}),
    #"Removed Other Columns" = Table.SelectColumns(#"Expanded Custom",{"Location", "Group", "Locations-Fill"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Other Columns",{{"Location", type text}, {"Group", Int64.Type}, {"Locations-Fill", type text}})
in
    #"Changed Type1"
 
Upvote 0
Here is another Power Query solution

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Location", type text}, {"Group", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Group"}, {{"Data", each _, type table [Location=nullable text, Group=nullable number]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Data],"Index",1,1)),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Location", "Index"}, {"Custom.Location", "Custom.Index"}),
    #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "Custom", each if [Custom.Index] =1 then [Custom.Location] else null),
    #"Filled Down" = Table.FillDown(#"Added Custom1",{"Custom"}),
    #"Removed Columns" = Table.RemoveColumns(#"Filled Down",{"Data", "Custom.Index"}),
    #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Custom.Location", "Group", "Custom"})
in
    #"Reordered Columns"
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top