Forum Discussion

maclura's avatar
maclura
Resolver I
4 years ago
Solved

Unpivoting challenge (multiple Excel files with multiple spreadsheets from a Sharepoint folder)

Hi, until now I manually managed to extract data from 2 Excel files located in a Sharepoint folder. One file was related to 2020 data and the other to 2021 data. Each Excel file contains 15 tabs w...
  • maclura's avatar
    maclura
    4 years ago

    Thank you wdx223_Daniel ,

    it does work, but the result is not exactly what I expected.

    I adapted your code in this way:

     

    let
        Source = SharePoint.Files("my Sharepoint path", [ApiVersion = 15]),
        #"Filtered Rows" = Table.SelectRows(Source, each Text.StartsWith([Name], "my text filter")),
        custom1=Table.Combine(List.TransformMany(#"Filtered Rows"[Content],each Excel.Workbook(_)[Data],(x,y)=>Table.UnpivotOtherColumns(y,{"Column1","Column2","Column3"},"End of Mounth","Value")))
    in
        custom1

     

    and this is the result

     

    At the end I solved my need with the following solution

    let
        Source = SharePoint.Files("my Sharepoint url", [ApiVersion = 15]),
        #"Filtered Rows" = Table.SelectRows(Source, each Text.StartsWith([Name], "my text filter")),
    
        WorkbookList = List.Transform(#"Filtered Rows"[Content], each Excel.Workbook(_)[Data]),
        SpreadsheetList = List.Combine(WorkbookList),
    
            TransformTable = (SpreadsheetList as list) as list => 
        let
            TransformedTable = List.Transform(
                SpreadsheetList, each 
                    Table.UnpivotOtherColumns(
                        Table.PromoteHeaders(_, [PromoteAllScalars=true]),
                        {"Col1", "Col2", "Col3"},
                        "Attribute", "Value"))
        in
        TransformedTable,
    
        SpreadsheetTable = Table.Combine(TransformTable(SpreadsheetList))
    
    in
        SpreadsheetTable

    Thank you again wdx223_Daniel for your answer, because helped me to understand better iterations in M, you deserve a Kudos!

    m