How do you get rid of extra delimiters when merging columns?

Monsignor

Board Regular
Joined
May 30, 2011
Messages
162
In a situation where not every column has a value, the Merge Columns feature adds a delimiter even if a cell is blank. Thus a result can be like:

IL,KS,,,,NY
,,,,,FL
,CA,,,,
GA,FL,,DC,KS,CA

rather than:
IL,KS,NY
FL
CA
GA,FL,DC,KS,CA


Basically, it'd be nice to recreate the new TEXTJOIN function and include the option to Ignore Blanks.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
few ways come to mind - 1 using SUBSTITUTE, another structuring a formula to not add them in the 1st place (also using substitute)

What does your raw data look like?
 
Upvote 0
Let's say I've done a lot of work in Power Query to get to this step and now I don't care about the Day 1 thru Day 7 headers. I just want all of the values pushed to the left.


delimiters.png
 
Upvote 0
Don't know if this will work in Query, but this is what I use if I need to do this...
=SUBSTITUTE(TRIM(B2&" "&B3&" "&B4&" "&B5&" "&B6&" "&B7&" "&B8&" "&B9&" "&B10)," ",",")
 
Upvote 0
That won't work in Power Query. In native Excel it'd be very easy to use TEXTJOIN and set it to "ignore blanks." Power Query makes a big mess.
 
Upvote 0
Thanks for the effort. PQ is messy in a lot of ways. Maybe in one of the monthly updates this problem with these excess delimiters will be fixed.
 
Upvote 0
Hi Monsignor,

This is one of those situations where I think you just have to modify the code generated by the interface.

I assume after you choose "Merge Columns" you get a line of code like this:
Code:
= Table.CombineColumns(PreviousStep, {"Day 1", "Day 2", "Day 3", "Day 4", "Day 5"}, [COLOR=#ff0000][B]Combiner.CombineTextByDelimiter(",", QuoteStyle.None)[/B][/COLOR], "Merged")

You can change the code as follows, to instead apply the Combiner function to the list with nulls removed:

Code:
= Table.CombineColumns(PreviousStep, {"Day 1", "Day 2", "Day 3", "Day 4", "Day 5"}, [B][COLOR=#ff0000]each Combiner.CombineTextByDelimiter(",", QuoteStyle.None)(List.RemoveNulls(_))[/COLOR][/B], "Merged")
 
Upvote 0
Ozeroth! YES!!! that's it! Thanks. Now, I have to study this and see how it works. But this is it.
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,930
Members
449,195
Latest member
Stevenciu

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