Forum Discussion

MRIZ's avatar
MRIZ
Helper II
2 years ago
Solved

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 1

csv 2:

csv 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. 

4 Replies

  • 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 
    • Anonymous's avatar
      Anonymous
      Not applicable

      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.

      Then you can append the table after tranforming.

      Output

       

      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.

       

       

    • Anonymous's avatar
      Anonymous
      Not applicable

      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