Forum Discussion
Splitting Data in multiple rows of single column into different columns
Hi!
Please can you look at the sample raw data and expected output here below which should help understand how the data is set up and the desired output.
I would like to be able to split the rows at every name ( or any other suggestion ) at the rest of the data can move into adjacent column
Can i request help in getting this done?
( Would like to get this done in power query preferably )
Sample raw data in notepad
Jack Reacher
4 purchases
3 Days ago
shoes
socks
others
harrypoter
2 purchases
10 Days ago
wands
owls
Ethan Hunt
10 Purchases
15 Days ago
gun
missile
sattelite
syringes
ariplanes
others
Expected Output
Thanks & regards
Dhritiman
6 Replies
- Riny_van_EekelenPlatinum Contributor
DhritimanL Since you explicitly asked for a PQ solution, I'm giving you just that. I suspect that your real data is much more complicated and you don't want a lot of manual interference with helper columns and complex formulae. Or do you just want to learn about PQ?
Just add to the blue table and refresh the green one, as long as you make sure that the Name is always in the row directly above the row that includes the string "urchase". PQ is case sensitive. This way, you will capture all occurrences of "purchases", "Purchases", "purchase" and "Purchase"
- DhritimanLCopper Contributor
Riny_van_Eekelen Thank you So much, yes indeed the actual data has other key words so i went ahead and edited the m-code and replaced "purchases" with the required words and a few other minor tweak to make it work like a charm for my data.
Much appreciated and grateful.
Thank you once again.
Kind regards
Dhritiman
- Riny_van_EekelenPlatinum Contributor
DhritimanL Glad you could fix it.
- Rajesh_SinhaIron Contributor
Your data has no uniformity like name intervals are not common therefore any single formula or method will not work properly. The simplest I can suggest is TRANSPOSE. Which need to use block wise.
Like Copy Jack Reacher to Others, then Harry potter to Owls and so next.
Another is this, possibly help you.
How it works:
- Put Helper data as show in Screen Shot.
- Formula in cell D89, finish with Enter & fill across.
=IFERROR(IF($C89=1,INDEX($A$89:$A$94,COLUMN(A1)),IF($C89=2,INDEX($A$95:$A$99,COLUMN(A1)),IF($C89=3,INDEX($A$100:$A$108,COLUMN(A1)),""))),"")
- Adjust cell references in the formula as needed.
- DhritimanLCopper Contributor
Rajesh_Sinha Thank you for the response, however if you notice there is a repeat pattern occurring which is the line ending as X purchases, I was hoping if I can find a way to leverage that.
I am positive there must bea way to break the data at that level and move the balance into the next column, we just need to figure out a way.
I'll keeping looking out for solutions, meanwhile if this point trigger something to you, do please help.
Regards
- MindreVetandeIron Contributor
If your serie starts in A1. Formulas from B1 to E1
B1=IF(ISNUMBER(SEARCH(" purchase",A2)),A1,"")
C1=IF(B1<>"",A2,"")
D1=IF(C1<>"",A3,"")
E1=IF(D1<>"",TEXTJOIN(" ",,OFFSET(A4,0,0,MATCH("* purchase*",A4:A10000,0)-2)),"")*****ED****
E-column will be wrong for the last post. try something like:
'=IF(D1<>"",TEXTJOIN(" ",,OFFSET(A4,0,0,IFERROR(MATCH("* purchase*",A3:A10000,0)-2,MATCH("*",A3:A10000,-1)))),"")