Combine 3 non-contiguous columns into one removing blanks - array help?

Emerlin

Board Regular
Joined
Jan 8, 2007
Messages
117
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have data in columns B2:B9, D2:D9 and F2:F9. Some of those cells have blanks.

I would like to combine them into one column in starting in J2 and ignore the blanks.

I know this is an array formula, and can get one column to work with this:
=IFERROR(INDEX($B$2:$B$9,SMALL(IF($B$2:$B$9<>"",ROW($B$2:$B$9)-ROW(B$2)+1),ROWS(J$2:J2))),"")

How can I add the other columns to the list...? I have tried multiple things with no success.

Thanks in advance for any all help.
 
Last edited:

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
so PowerQuery = Get&Transform section under Data Tab

WOW -this is pretty powerful. I can't believe I have never found this. I am playing with it now. I wonder if there is a way for it auto update if the table data changes. I am having fun with it.

Thanks again.
 
Upvote 0
Sure,

so with your example here is PQ solution


[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#5B9BD5]A[/td][td=bgcolor:#5B9BD5]B[/td][td=bgcolor:#5B9BD5]C[/td][td=bgcolor:#5B9BD5]D[/td][td=bgcolor:#5B9BD5]E[/td][td=bgcolor:#5B9BD5]F[/td][td][/td][td=bgcolor:#70AD47]Column1[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7]red[/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7]orange[/td][td][/td][td=bgcolor:#E2EFDA]red[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td]blue[/td][td][/td][td]red[/td][td][/td][td][/td][td][/td][td]blue[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7]yellow[/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7][/td][td][/td][td=bgcolor:#E2EFDA]yellow[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td]green[/td][td][/td][td]white[/td][td][/td][td]black[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7]black[/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7]yellow[/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7]blue[/td][td][/td][td=bgcolor:#E2EFDA]red[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]green[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td=bgcolor:#E2EFDA]yellow[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]orange[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td=bgcolor:#E2EFDA]white[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]blue[/td][/tr]
[/table]


Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Removed Other Columns" = Table.ToColumns(Table.SelectColumns(Source,{"B", "D", "F"})),
    #"Converted to Table" = Table.FromList(#"Removed Other Columns", Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandListColumn(#"Converted to Table", "Column1"),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Column1", each ([Column1] <> null))
in
    #"Filtered Rows"[/SIZE]
 
Upvote 0
Sure,

so with your example here is PQ solution


[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#5B9BD5]A[/td][td=bgcolor:#5B9BD5]B[/td][td=bgcolor:#5B9BD5]C[/td][td=bgcolor:#5B9BD5]D[/td][td=bgcolor:#5B9BD5]E[/td][td=bgcolor:#5B9BD5]F[/td][td][/td][td=bgcolor:#70AD47]Column1[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7]red[/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7]orange[/td][td][/td][td=bgcolor:#E2EFDA]red[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td]blue[/td][td][/td][td]red[/td][td][/td][td][/td][td][/td][td]blue[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7]yellow[/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7][/td][td][/td][td=bgcolor:#E2EFDA]yellow[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td]green[/td][td][/td][td]white[/td][td][/td][td]black[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7]black[/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7]yellow[/td][td=bgcolor:#DDEBF7][/td][td=bgcolor:#DDEBF7]blue[/td][td][/td][td=bgcolor:#E2EFDA]red[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]green[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td=bgcolor:#E2EFDA]yellow[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]orange[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td=bgcolor:#E2EFDA]white[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]blue[/td][/tr]
[/table]


Code:
[SIZE=1]let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Removed Other Columns" = Table.ToColumns(Table.SelectColumns(Source,{"B", "D", "F"})),
    #"Converted to Table" = Table.FromList(#"Removed Other Columns", Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandListColumn(#"Converted to Table", "Column1"),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Column1", each ([Column1] <> null))
in
    #"Filtered Rows"[/SIZE]

At this risk of looking like a dunce.... Is what you posted to be appended to the original code? The # is a rem out correct? I am unsure what to do with the code provided above.

Thanks again for your efforts
 
Last edited:
Upvote 0
This is for your example from post#3 and expected result
if your source table (Excel Table not a range) has name Table1 and header of columns are B, D, F you can copy code and paste into advanced editor
if not - change table name and headers in code

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="[B][COLOR="#FF0000"]Table1[/COLOR][/B]"]}[Content],
    #"Removed Other Columns" = Table.ToColumns(Table.SelectColumns(Source,{"[B][COLOR="#FF0000"]B[/COLOR][/B]", "[B][COLOR="#FF0000"]D[/COLOR][/B]", "[B][COLOR="#FF0000"]F[/COLOR][/B]"})),
    #"Converted to Table" = Table.FromList(#"Removed Other Columns", Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Expanded Column1" = Table.ExpandListColumn(#"Converted to Table", "Column1"),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Column1", each ([Column1] <> null))
in
    #"Filtered Rows"

but usually PQ solutions are not copy/paste solutions :laugh:
 
Last edited:
Upvote 0
Ugh.... very sorry. Now I understand. Thank you so much for the link.

last thing - can PQ auto refresh if the table data is changed?
 
Upvote 0
2016 desktop
I'm not sure if that means the stand-alone version of Excel 2016 or through Office 365. If through Office 365, then ..

a) If you are not concerned about the particular order of the results, try J2. This is an array formula so should be entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}. The formula can then be copied down.

b) If you want the particular order you gave, then try K2 (does not require the Ctrl+Shift+Enter confirmation.

Both will update automatically if the source data changes.

Excel Workbook
BCDEFGHIJK
1
2redorangeredred
3blueredorangeblue
4yellowblackblueyellow
5greenwhiteredblack
6blackyellowblueyellowred
7blackgreen
8greenyellow
9whiteorange
10blackblack
11yellowwhite
12blueblue
13
List data
 
Upvote 0
I'm not sure if that means the stand-alone version of Excel 2016 or through Office 365. If through Office 365, then ..

a) If you are not concerned about the particular order of the results, try J2. This is an array formula so should be entered without the {} but confirmed with Ctrl+Shift+Enter, not just Enter. If confirmed correctly, Excel will insert the {}. The formula can then be copied down.

b) If you want the particular order you gave, then try K2 (does not require the Ctrl+Shift+Enter confirmation.

Both will update automatically if the source data changes.

Excel Workbook
BCDEFGHIJK
1
2redorangeredred
3blueredorangeblue
4yellowblackblueyellow
5greenwhiteredblack
6blackyellowblueyellowred
7blackgreen
8greenyellow
9whiteorange
10blackblack
11yellowwhite
12blueblue
13
List data

Thank you for your efforts - I am using stand alone, desktop version of Excel 2016.
 
Upvote 0
Ugh.... very sorry. Now I understand. Thank you so much for the link.

last thing - can PQ auto refresh if the table data is changed?

After change something in source data you can use Ctrl+Alt+F5 to refresh query table or use a little vba code to refresh it OnChange
 
Upvote 0

Forum statistics

Threads
1,223,956
Messages
6,175,611
Members
452,660
Latest member
Zatman

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