• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Lift and shift row data to the left|Power Query|Excel Forum|My Online Training Hub

You are here: Home / Lift and shift row data to the left|Power Query|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumPower QueryLift and shift row data to the left
sp_PrintTopic sp_TopicIcon
Lift and shift row data to the left
Avatar
Shannon Scott
Member
Members

Dashboards

Power BI

Power Pivot
Level 0
Forum Posts: 10
Member Since:
May 8, 2018
sp_UserOfflineSmall Offline
1
June 2, 2018 - 8:20 am
sp_Permalink sp_Print

Hi Mynda,

I'm loving your Power Query course and am so excited about all the possibilities this new found knowledge has opened up! Thank you!

I'm working on one of my projects as I progress through the course but I've come across a data cleaning issue that isn't addressed in your course so I'm hoping for some guidance.

I've attached a dummy file as an example. The data I'm receiving is on the 'Raw Data' tab, the output I'm looking for is on the 'Cleaned Data' tab. Basically, I need to lift and shift columns P-AC into column B-O for rows 5-7. Actual raw data files will have over 14,000 records and this issue is found throughout. 

Any help you can provide is appreciated!

Thanks!

Shannon

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
June 3, 2018 - 3:26 pm
sp_Permalink sp_Print sp_EditHistory

Hi Shannon,

Keep in mind that Power Query does not preserve all the time the order of the columns , in some cases, after some specific operations not even the rows order will be the same. (you have to add an index column at the very first steps, then sort after this column if the rows are scrambled, in rare cases when you need to have the same order of rows as the initial data)

The columns are sorted alphabetically, so you have to refer to column names instead of column numbers, otherwise you might mess up the data.

Add an index column, then for each column you want to change add a new column to create the final value for that:

= if ([Index]>4 and [Index]<8) then [textbox9] else [textbox7]

This will be the easy way. It is possible to setup a settings table, to indicate the row index, source and destination column names and write the query to transform the existing columns, but it's more complex.

One way is to setup a simple table with indexes of the records that must be changed, create a function that can check if the current row index is in the list of indexes where data must be taken from another column, and just replace the column values.

A function that will check if the current row index is in the indexes table:

(index)=>
let
Source = Excel.CurrentWorkbook(){[Name="Table3"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Index", Int64.Type}}),
Index = try (Table.SelectRows(#"Changed Type", each ([Index] = index)){0}[Index]<>null) otherwise false
in
Index

Then use this function in .ReplaceValue function, if the index is in the index table, data will be taken from the other column:

ReplaceColumn3 = Table.ReplaceValue(ReplaceColumn2 ,each [category2], each (if IsInRowsTable([Index]) then [category3] else [category2]), Replacer.ReplaceValue,{"category2"})

File attached. (I replaced only 3 columns, you have to add another step for each column you want to replace.)

Anoher improvement might be to use a row iterator to loop through a table containing the column names that must be replaced, if there are too many columns.

Avatar
Shannon Scott
Member
Members

Dashboards

Power BI

Power Pivot
Level 0
Forum Posts: 10
Member Since:
May 8, 2018
sp_UserOfflineSmall Offline
3
June 6, 2018 - 8:10 am
sp_Permalink sp_Print

Hi Catalin,

I was working through your index column suggestion but then realized that it won't work because I will be adding data every month and the max index will always be changing.

I'm new to Power Query so it's taking me a bit to wrap my head around the function you suggested. I guess if the indexes table updated every month then this could work...something to play with.

Thanks for the suggestions!

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
June 6, 2018 - 4:14 pm
sp_Permalink sp_Print

You have to provide a criteria to power query, to identify the rows where data should be taken from another column.

You mentioned row numbers, so I used a row index table to setup the query.

If there is a good indication inside the data table to tell if data should be taken from another column, then we can use that, but you have to identify a good criteria for that.

Avatar
Shannon Scott
Member
Members

Dashboards

Power BI

Power Pivot
Level 0
Forum Posts: 10
Member Since:
May 8, 2018
sp_UserOfflineSmall Offline
5
June 7, 2018 - 3:00 am
sp_Permalink sp_Print

Success!

= Table.AddColumn(#"Added Conditional Column9", "Custom.10", each if [category2] = null then [Textbox12] else [Textbox10])

I basically recreated all the columns I needed using this criteria.

Thanks for your help!

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Velouria, Riny van Eekelen, YANINA TRIGO
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Sopi Yuniarti
LAFONSO HERNANDEZ
Hayden Hao
Angela chen
Sean Moore
John Chisholm
Forum Stats:
Groups: 3
Forums: 24
Topics: 6216
Posts: 27250

 

Member Stats:
Guest Posters: 49
Members: 31897
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.