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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
LaurentZ
Helper I
Helper I

Get Data from Folder wich are not 100% the same

Hi,

 

I've 4 CSV (with TAB as separator) files each month that I need to append.

So I use the "Import from Folder" feature in PowerQuery.

 

Those CSV files are extracted from SAP in a way that I can't control the output myself.

 

They are quite similar:

11 lines with ABAP parameters that I have to remove,

then on line 12 the header (same headers)

then a blank line

then data

 

My problem is the following: sometime I've a shift of column and a data that is in column D for 3 files, is in column C in the fourth one... the header is the same - but it's still considered as a line of data at thise stage, because it's not promoted yet.

 

The problem would be solved by doing a thing like that:

1. read the file, remove the 11 lines, promote header, if the column name is empty then remove the entire column,

2. read the second file, do the same, and then append the result to the first file... as header are the same, I won't have column shift anymore and continue with file 3 and 4...

... the problem is that I don't know how to do that or it's even possible?

 

Do you have a solution ?

Thank you

 

note that I'm using PowerQuery, not PowerBI so it can't be in M language.

 

 

 

 

 

1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

FYI that PowerQuery in Excel also use M language; the query editor is the same in both.  What you are describing is doable.  Here is one way.

 

1.  Use the Folder connector to go to the folder with your 4 csv files, and choose Combine & Transform (or something close to that)

2. That will generate a bunch of stuff in the query editor, including a function and a Transform Sample File query (that is tied to that function)

3.  In the Transform Sample File query, do the following transformations

- remove top 11 rows

- promote headers

-filter out blanks (in any one of the columns)

- Ctrl-click the 3 (or 4) columns you want to keep, right click and choose Remove Other Columns

4.  Go to your main query at the bottom (the one with an Invoked Custom Function step that used the function, now updated with your new steps).  If all the remaining columns are the same in the 4 files, all the data should be combined in that query.

5.  Do any additional transformations needed

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

2 REPLIES 2
mahoneypat
Microsoft Employee
Microsoft Employee

FYI that PowerQuery in Excel also use M language; the query editor is the same in both.  What you are describing is doable.  Here is one way.

 

1.  Use the Folder connector to go to the folder with your 4 csv files, and choose Combine & Transform (or something close to that)

2. That will generate a bunch of stuff in the query editor, including a function and a Transform Sample File query (that is tied to that function)

3.  In the Transform Sample File query, do the following transformations

- remove top 11 rows

- promote headers

-filter out blanks (in any one of the columns)

- Ctrl-click the 3 (or 4) columns you want to keep, right click and choose Remove Other Columns

4.  Go to your main query at the bottom (the one with an Invoked Custom Function step that used the function, now updated with your new steps).  If all the remaining columns are the same in the 4 files, all the data should be combined in that query.

5.  Do any additional transformations needed

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Ok, thank you for the solution... I didn't know who could change the transformation file (I'm a beginner).

It works!

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors