Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
dilumd
Solution Supplier
Solution Supplier

Reorder column headers for apend

Hi All,

 

I have few files which need to be appended,

 

However, my problem is that columns are keep on chnaging every month (e.g. order of the column, new columns can be added or deleted). so inorder to append i need to adjust the all columns in order and take additional columns towards the end of the appended new table. (however i have about 50 to 60 columns each month and i need to append 6 month's data) 

 

Is there a easy way of doing this???

 

I tried reorder columns but i'm getting an error since some columns are missing in some months and some new columns are added

 

Month 1EPF NoBasic SalaryAttendance IncentiveProduction IncentiveGross SalaryTaxesWalfareNet salary  
Month 2EPF NoBasic SalaryAttendance IncentiveProduction IncentiveAllowance_1Gross SalaryTaxesWalfareNet salary 
Month 3EPF NoBasic SalaryAttendance IncentiveGross SalaryTaxesWalfareNet salary   
Month 4EPF NoBasic SalaryAttendance IncentiveProduction IncentiveAllowance_1Allowance_2Gross SalaryTaxesWalfareNet salary

 

 Thank you in advance.

1 ACCEPTED SOLUTION

Hi All,

 

Thank you for your respond, however my data files have more than 100 columns every month and it’s changing so it’s a nightmare to combine manually. 

 

I tried below R script on power BI and got it sorted without any problem.

 

Please refer the below code if you’ll also come across similar issue in future.

 

Thanks again for the respond.

 

setwd("C:/Users/..../ Files")
library(xlsx)

Dec=read.xlsx("Dec 16.xlsx",1,startRow=5,header=TRUE)
Jan=read.xlsx("Jan 17.xlsx",1,startRow=5,header=TRUE)
Feb=read.xlsx("Feb 17.xlsx",1,startRow=5,header=TRUE)
Mar=read.xlsx("Mar 17.xlsx",1,startRow=5,header=TRUE)
Apr=read.xlsx("Apr 17.xlsx",1,startRow=5,header=TRUE)
May=read.xlsx("May 17.xlsx",1,startRow=5,header=TRUE)
Jun=read.xlsx("Jun 17.xlsx",1,startRow=5,header=TRUE)

library(plyr)

combine=rbind.fill(Dec,Jan,Feb,Mar,Apr,May,Jun)

View solution in original post

5 REPLIES 5
v-chuncz-msft
Community Support
Community Support

@dilumd,

 

I agree with the comment above. You may select Unpivot Columns in the Query Editor and use Matrix visual later.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

Well, if we are talking 6 files here, the easiest thing might be to just go into the source and fix them all manually to be the same format. Brute force, but effective. Otherwise, you might be able to do something with Transpose of pivoting, but if you are missing columns in some files that's going to be really tough because you'd have to add those columns effectively but how do you know to add a column that may or may not be added at some future point in time.

 

In the cases where I have run into similar issues, I have tended to format my source data like:

 

My Metric 1, ##

My Metric 2, ##

My Metric 3, ##

 

I can then Transpose this to columns. In this way, if columns are added to the end it generally isn't a problem in a combine binaries query.

 

Will think about it some more.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi All,

 

Thank you for your respond, however my data files have more than 100 columns every month and it’s changing so it’s a nightmare to combine manually. 

 

I tried below R script on power BI and got it sorted without any problem.

 

Please refer the below code if you’ll also come across similar issue in future.

 

Thanks again for the respond.

 

setwd("C:/Users/..../ Files")
library(xlsx)

Dec=read.xlsx("Dec 16.xlsx",1,startRow=5,header=TRUE)
Jan=read.xlsx("Jan 17.xlsx",1,startRow=5,header=TRUE)
Feb=read.xlsx("Feb 17.xlsx",1,startRow=5,header=TRUE)
Mar=read.xlsx("Mar 17.xlsx",1,startRow=5,header=TRUE)
Apr=read.xlsx("Apr 17.xlsx",1,startRow=5,header=TRUE)
May=read.xlsx("May 17.xlsx",1,startRow=5,header=TRUE)
Jun=read.xlsx("Jun 17.xlsx",1,startRow=5,header=TRUE)

library(plyr)

combine=rbind.fill(Dec,Jan,Feb,Mar,Apr,May,Jun)

R to the rescue!


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Yes!!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.