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
OKgo
Advocate II
Advocate II

Appended CSVs, searching rows to promote headers

 

 

 

 

Target format

03 PBI.JPG

 

The raw data is many CSV files appended together. Some CSVs contain more columns than others:

02 PBI.JPG01 PBI.JPG

 

My plan is to unpivot this data to the target format. Where I am struggling is trying to isoloate / search the correct row to promote to headers. Thank you in advance

 

9 REPLIES 9
v-juanli-msft
Community Support
Community Support

Hi @OKgo

Please look at my test

2.png

Above it is an original table called “Sheet2”, it has five columns needed to be unpivot and two columns don’t need to unpivot.

1.Then I make a copy of “Sheet2”, thus a new table called “Sheet2copy”.

In this table, you could click on the “setting” icon on the “APPLIED STEPS” pane to see the detailed operation I made.

First, I select all columns and click “Transform->Replace Values”, then replace “null” with “0”,

Second, I add a conditional column(called “Custom”) to define which row contains date type value and which row contains number type value.

Third, I select the five columns(column1-5) and click on “unpivot the selected columns”.

3.png

2. create a blank query called “Query2”, and write code In Advanced editor

let

    Source1 = Sheet2copy,

    Source2 = Table.SelectRows(Source1,each[Custom]="number")

in

Source2

4.png

3.make a copy of Sheet2copy, the new table is called “Sheet2copy (2)”

then click on “Keep Rows->Keep Range of Rows” to keep the rows which “Custom” is “date”,

Then merge queries by column “Attribute” between “Sheet2copy (2)” and “Query2”,

5.png

6.png

 

 

Best regards

maggie

 

Hi Maggie

Thank you so much. I should have explained better. A large number and unknown number of CSV files are contained in a folder.  Using the expanded data function they are combined. They can not be merged/appended as the headers do not match. Here is an example of two CSV files appened together.

 

Columns A to E have consisent headers in the data.

Columns F onwards are alwasy the first day of the month or blank.

I do not konw how to create  a custom colum to return Row 1 = Date, Row 2 = Number

PBI5.JPG

 

Many thanks

 

Hi,

Check the linked file https://www.dropbox.com/s/6pdix2vg1dl27l1/Append%20CSV%20PQ.xlsx?dl=0

 

will this solution works for you?

Ashish_Mathur
Super User
Super User

Hi,

 

What if you do not promote headers but just use "Unpivot other columns"?  Does that work?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Unfortuneatly not. Then I have one column of values and one column of mixed values "MMM-YY" and "ColumnX", "ColumnY" etc...

I guess this is happening because the headers on each CSV file are not and can not be the same because they are dates.  I think i can solve this problem, if you can:

 

  1. Have one header row per file with only the day portion of the date as a header.  So if the header for column B's data is 17/7/2018, change it to 17 only.  This way there will only be 31 headers (columns) for all CSV files put together.
  2. Each CSV file name should carry the month name and Year

Can you carry out the 2 changes suggested above?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

1.Have one header row per file with only the day portion of the date as a header. So if the header for column B's data is 17/7/2018, change it to 17 only. This way there will only be 31 headers (columns) for all CSV files put together.
OKgo Response:  The columns are months (MMM-YY). Thankfully not days. Having upto 10 years (120 months) of columns is common. There are also 5 or so text columns with other peices of information that do not need to be unpivoted. With your suggusted approach this would make the data set very difficult to analyse and break all my exisiting measures.

2. Each CSV file name should carry the month name and Year

OKgo Response: Typically 6 x CSVs with between 100 months and 120 months of data. I don't quite understand the value of doing this.

Hi,

 

I cannot think of any other technique.  Since the header in every file is different, the append comand is not working.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thanks Ashish, I try a dummy CSV file tomorrow with just the headers and filename that will appear first in order to promote them. Not an elgant work around but hopefully it works.

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.