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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
MRIZ
Helper II
Helper II

Merging multiple CSVs and managing their dynamic Columns

I am new to Power Query. I am stuck in a situation . I will try to explain what i am trying and what i want to achieve. 
I have a sharepoint repo, where I may have multiple CSVs present in multiple folders. For example 
Parrent Folder / Child Folder A / EVT-ADT.csv
Parrent Folder / Child Folder B / EVT-ADT.csv
Attached csv file structure.  There are few things to note:
Both CSVs has same nature of data but for different projects. 
Both CSVs has these columns same Activity ID, Activity Name, Project ID, Project Name, Spreadsheet Field

Both CSVs might have same or different columns having DATES in it. 
Both CSVs has first ROW containg EVT-ADT.

csv 1:

csv 1csv 1

csv 2:

csv 2csv 2

 

Below are my requirements:
1- Loaded these files in Power BI (Done). 
2- Added a column which will have TABLE from BINARY (content) (Done)

= Table.AddColumn(#"Filtered Rows5", "Transform File (12)", each #"Transform File (12)"([Content]))
3- Expended the TABLEs column (Done). This step expended all tables and merged them. This output contains all the rows from both CSVs. 
= Table.ExpandTableColumn(#"Invoke Custom Function1", "Transform File (12)", Table.ColumnNames(#"Transform File (12)"(#"Sample File (12)")))
4- I want to remove the first ROW from each file (Done). 
5- Now tricky part starts. I want to make a generic columns for both the CSVs  so that both CSVs act as one file. below columns should be same but the columns having DATEs in it will be dynamic. The DATES column that are same in both CSVs will appear once but will contain cell values of there relevent files. The DATEs columns which are not same will becom new column (NEED HELP) Activity ID, Activity Name, Project ID, Project Name, Spreadsheet Field

I hope I am able to explain my issue. so plz  help me out. 

Tks. 

Rizwan. 

1 ACCEPTED SOLUTION
MRIZ
Helper II
Helper II

I have found solution in this good video. 
https://youtu.be/UaPrpQOchFI?si=znjbz1oAcPg2uDS_ 

Thanks,

Rizwan.

View solution in original post

4 REPLIES 4
MRIZ
Helper II
Helper II

I have found solution in this good video. 
https://youtu.be/UaPrpQOchFI?si=znjbz1oAcPg2uDS_ 

Thanks,

Rizwan.

Hi @MRIZ 

I'm glad you found a solution, and if the solution I provide can also help you, you can consider marking it as a solution so that it can be used as a reference for more people.

 

Best Regards!

Yolo Zhu

 

MRIZ
Helper II
Helper II

CSV 1:

EVT-ADT                     
Activity IDActivity NameProject IDProject NameSpreadsheet Field4/14/20245/14/20246/14/20247/14/20248/14/20249/14/202410/14/202411/14/202412/14/20241/15/20242/15/20243/15/20244/15/20245/15/20246/15/20247/15/20248/15/2024
 CPK-CS-D14-CE-P1-1Escalator - Arcade 1TKAR2-ICCM-UPEarned Value Cost                
    Earned Value Labor Units               
    Planned Value Cost         ################     
    Planned Value Labor Units        4691290     
    Estimate To Complete          ########    
    Estimate To Complete Labor Units         1758    

 

CSV 2: 

EVT-ADT                   
Activity IDActivity NameProject IDProject NameSpreadsheet Field23-Dec24-Jan24-Feb24-Mar24-Apr24-May24-Jun24-Jul24-Aug24-Sep24-Oct24-Nov24-Dec25-Jan25-Feb
 HP.CN.EXT.1010Swimming Pool (Structure, Finishing & Equipment)HPH W23 23-05HPH Rev 02 BL1 Rev 03 W23 23-05Earned Value Cost              
    Earned Value Labor Units             
    Planned Value Cost         57,383.21################8,197.60 
    Planned Value Labor Units        5692031219481 
    Estimate To Complete        57,383.21################8,197.60 
    Estimate To Complete Labor Units       5692031219481 

Hi @MRIZ 

You can custom a function as the follwing.

 

(a as table)=>
    let 
    #"Promoted Headers" = Table.PromoteHeaders(a, [PromoteAllScalars=true]),
    #"Added Index" = Table.AddIndexColumn(#"Promoted Headers", "Index", 1, 1, Int64.Type),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Activity ID", "Activity Name", "Project ID", "Project Name", "Spreadsheet Field","Index"}, "Attribute", "Value"),
    Custom1 = Table.TransformColumns(#"Unpivoted Other Columns",{"Attribute", each if Text.Contains(_,"-") then _ else  Date.ToText(Date.FromText(_),[Format="yy-MMM"])}),
    #"Changed Type" = Table.TransformColumnTypes(Custom1,{{"Value", type number}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Activity ID", "Activity Name", "Project ID", "Project Name", "Spreadsheet Field", "Index", "Attribute"}, {{"Sum", each List.Sum([Value]), type nullable number}}),
    #"Replaced Value" = Table.ReplaceValue(#"Grouped Rows",null,0,Replacer.ReplaceValue,{"Sum"}),
    #"Pivoted Column" = Table.Pivot(#"Replaced Value", List.Distinct(#"Replaced Value"[Attribute]), "Attribute", "Sum"),
    #"Removed Columns" = Table.RemoveColumns(#"Pivoted Column",{"Index"})
in
    #"Removed Columns"

 

Then select the table in this function.

vxinruzhumsft_0-1723000109573.png

Then you can append the table after tranforming.

vxinruzhumsft_1-1723000209475.png

Output

vxinruzhumsft_0-1723004399429.png

 

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.