Forum

Shift cells to righ...
 
Notifications
Clear all

Shift cells to right in power query

2 Posts
2 Users
0 Reactions
558 Views
(@nanak)
Posts: 1
New Member
Topic starter
 

Hi. I need with the sample table below in power query. I have 1000+rows. 

Is it possible to shift cells to right so that 'last name'  text comes in one column and same with optional as one column just like first name and middle name column? Kind of like four types of data- First name, middle name, last name, optional. But data is uneven. Thanks. 

First name Mike Middle name Ja Last name   Optional MJ        
First name Tyson Middle name He Also Sera Last name aa Optional TA      
First name Jake Middle name martin Tyson Last name aab bbb c d Optional JT
First name Sam Middle name Patel hara paulini   last name dg gh Optional ST
First name Matt Middle name Johnson  Singh Used Last name bb Optional MK    
First name John Middle name jake Last name hillman robertson Optional JR      
First name Paul Middle name Ku Last name ali Optional PK        
                       
 
Posted : 21/08/2021 2:18 pm
(@catalinb)
Posts: 1937
Member Admin
 

Hi Navneet,

There is no cell shifting in PQ, but you can perform other operations to join the names for example:

Add this step:

= Table.AddColumn(Source, "Custom", (x)=> Text.Combine(List.RemoveNulls(List.RemoveItems(List.FirstN(Record.ToList(x),List.PositionOf(Record.ToList(x),"Optional")),{"First name","Middle name","Last name"}))," "))

I did this in one step, but you can do it one step at a time: first convert to a list: Table.AddColumn(Source, "Custom", (x)=>Record.ToList(x)), then keep all before Optional item (List.FirstN), remove first-middle-Last entries, then remove nulls.

This will join all name pieces into one text, like: "Jake martin Tyson aab bbb c d" from your example.

This way, you can do any operations on the current row: for example, after you join names, you can keep all items after the Optional value, using the same technique.

 
Posted : 23/08/2021 1:09 am
Share: