<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Sorting multi header table in power query in Power Query</title>
    <link>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4161811#M136751</link>
    <description>&lt;P&gt;Morning, I have folder that reiceves multiple files in it and I will be reading all the files from that folder and combining them.&lt;BR /&gt;Good thing is that tables in the csv files are all some layout.&lt;BR /&gt;The problem is the layout looks like this:&lt;BR /&gt;&lt;img /&gt;&amp;nbsp;&lt;BR /&gt;I highlited what should be each independent column in same colors.&lt;BR /&gt;&lt;STRONG&gt;Exception to red: red parts of the table are not required in final sorted table.&lt;/STRONG&gt;&lt;BR /&gt;As you see pick storage column spans acros all other columns(Orders, line qty and Pending(IM)).&lt;BR /&gt;This is how final result should look like:&lt;BR /&gt;&lt;img /&gt;&amp;nbsp;&lt;BR /&gt;As you see final result would be easier to work with and it does not introduce that many new rows and removes large amount of additional columns.&lt;/P&gt;&lt;P&gt;I did try to unpivot or transpose table in order to sort it out but was not successfull at the moment.&lt;BR /&gt;I could really use some help.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I attached sample data to this link.&lt;BR /&gt;&lt;A href="https://we.tl/t-eaLcw9LvSC" target="_blank"&gt;https://we.tl/t-eaLcw9LvSC&lt;/A&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Fri, 20 Sep 2024 08:47:42 GMT</pubDate>
    <dc:creator>Justas4478</dc:creator>
    <dc:date>2024-09-20T08:47:42Z</dc:date>
    <item>
      <title>Sorting multi header table in power query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4161811#M136751</link>
      <description>&lt;P&gt;Morning, I have folder that reiceves multiple files in it and I will be reading all the files from that folder and combining them.&lt;BR /&gt;Good thing is that tables in the csv files are all some layout.&lt;BR /&gt;The problem is the layout looks like this:&lt;BR /&gt;&lt;img /&gt;&amp;nbsp;&lt;BR /&gt;I highlited what should be each independent column in same colors.&lt;BR /&gt;&lt;STRONG&gt;Exception to red: red parts of the table are not required in final sorted table.&lt;/STRONG&gt;&lt;BR /&gt;As you see pick storage column spans acros all other columns(Orders, line qty and Pending(IM)).&lt;BR /&gt;This is how final result should look like:&lt;BR /&gt;&lt;img /&gt;&amp;nbsp;&lt;BR /&gt;As you see final result would be easier to work with and it does not introduce that many new rows and removes large amount of additional columns.&lt;/P&gt;&lt;P&gt;I did try to unpivot or transpose table in order to sort it out but was not successfull at the moment.&lt;BR /&gt;I could really use some help.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I attached sample data to this link.&lt;BR /&gt;&lt;A href="https://we.tl/t-eaLcw9LvSC" target="_blank"&gt;https://we.tl/t-eaLcw9LvSC&lt;/A&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 08:47:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4161811#M136751</guid>
      <dc:creator>Justas4478</dc:creator>
      <dc:date>2024-09-20T08:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting multi header table in power query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4162912#M136808</link>
      <description>&lt;P&gt;For each header column where the contents does not sort naturally you need to provide a dedicated sort column and then use the "sort one column by another column"&amp;nbsp; feature.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 15:43:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4162912#M136808</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-09-20T15:43:21Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting multi header table in power query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4162926#M136809</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="100342" data-lia-user-login="lbendlin" class="lia-mention lia-mention-user"&gt;lbendlin&lt;/a&gt;&amp;nbsp;I am not sure if that is going to help in my case since my data looks like this:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;When I import it in to power bi thats why I need to sort it in power query before I use it in report.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 15:54:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4162926#M136809</guid>
      <dc:creator>Justas4478</dc:creator>
      <dc:date>2024-09-20T15:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting multi header table in power query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4162957#M136813</link>
      <description>&lt;P&gt;In my data 'Pick Storage' which is in column two, row one.&lt;BR /&gt;Rest in row one G2P1, G2P5 and G5P0 are values of 'Pick Storage' column that ideally should be across one column and not multiple rows.&lt;BR /&gt;Something like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;I hope it makes it more clear.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 16:05:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4162957#M136813</guid>
      <dc:creator>Justas4478</dc:creator>
      <dc:date>2024-09-20T16:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting multi header table in power query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4163441#M136842</link>
      <description>&lt;P&gt;Create a function that ingests a single file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;(f)=&amp;gt;
let
    Source = Csv.Document(f,[Delimiter=",",  Encoding=65001, QuoteStyle=QuoteStyle.None]),
    LZ = List.Skip(List.Transform(List.Zip({Record.ToList(Source{0}),Record.ToList(Source{1})}),each Text.Combine(_,"|")),2),
    #"Removed Bottom Rows" = Table.RemoveLastN(Source,1),
    #"Removed Top Rows" = Table.Skip(#"Removed Bottom Rows",2),
    #"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
    #"Replaced Headers" = Table.RenameColumns(#"Promoted Headers",List.Zip({List.Skip(Table.ColumnNames(#"Promoted Headers"),2),LZ})),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Replaced Headers", {"Status", "Created Date"}, "Attribute", "Value"),
    #"Split Column by Delimiter" = Table.SplitColumn(#"Unpivoted Other Columns", "Attribute", Splitter.SplitTextByEachDelimiter({"|"}, QuoteStyle.Csv, false), {"Pick Storage", "Attribute"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Value", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type", each ([Value] &amp;lt;&amp;gt; null) and ([Pick Storage] &amp;lt;&amp;gt; "Totals")),
    #"Pivoted Column" = Table.Pivot(#"Filtered Rows", List.Distinct(#"Filtered Rows"[Attribute]), "Attribute", "Value"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Pivoted Column",{{"Created Date", type date}},"de")
in
    #"Changed Type1"&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then apply that to the list of files&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And finally expand the table.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 23:24:01 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4163441#M136842</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-09-20T23:24:01Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting multi header table in power query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4163594#M136850</link>
      <description>&lt;P&gt;replace path_to_folder string with yours&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    transform_csv = (csv as binary) =&amp;gt; 
        [data = Csv.Document(csv,[Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.None]),
        storage = List.Buffer(List.RemoveLastN(List.Alternate(List.Skip(Record.ToList(data{0}), 2), 2, 1), 1)), 
        tx = List.TransformMany(
            Table.ToRows(Table.RemoveLastN(Table.Skip(data, 3), 1)),
            (x) =&amp;gt; ((w) =&amp;gt; 
                List.Zip(
                    {
                        storage, 
                        List.Alternate(w, 2, 1 , 1),
                        List.Skip(List.Alternate(w, 2, 1, 2)),
                        List.Alternate(w, 2, 1)
                    }
                )
            )(List.RemoveLastN(List.Skip(x, 2), 3)),
        (x, y) =&amp;gt; List.FirstN(x, 2) &amp;amp; y
        ),
        z = Table.FromRows(
            List.Select(tx, (x) =&amp;gt; x{3} &amp;lt;&amp;gt; ""), 
            {"Status", "Created Date", "Pick Storage", "Orders", "Line Qty", "Pending"})]
        [z],
    result = Table.Combine(List.Transform(Folder.Files("PATH_TO_FOLDER_WITH_FILES")[Content], transform_csv))
in
    result&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2024 06:03:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4163594#M136850</guid>
      <dc:creator>AlienSx</dc:creator>
      <dc:date>2024-09-21T06:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting multi header table in power query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4163660#M136854</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="306002" data-lia-user-login="Justas4478" class="lia-mention lia-mention-user"&gt;Justas4478&lt;/a&gt;,&amp;nbsp;another approach:&lt;/P&gt;
&lt;P&gt;Replace address to your folder with csv files in &lt;STRONG&gt;Source&lt;/STRONG&gt; step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;LI-CODE lang="javascript"&gt;let
    fn_Transform = 
      (tbl as table)=&amp;gt; 
        [
          // _Detail = ContentToTable{0}[Content],
          _Detail = tbl,

          _Helper = [ colNames = Table.ColumnNames(_Detail),
          totalsPos = List.PositionOf(Record.ToList(Table.First(_Detail)), "Totals", Occurrence.All),
          colNamesToRemove = List.Transform(totalsPos, (x)=&amp;gt; colNames{x}) ],
          _RemovedTotalsColumns = Table.RemoveColumns(_Detail, _Helper[colNamesToRemove]),
          _RemovedTotalsRow = Table.SelectRows(_RemovedTotalsColumns, each ([Column1] &amp;lt;&amp;gt; "Totals")),
          _Transposed = Table.FromColumns(Table.ToRows(_RemovedTotalsRow)),
          _MergedHeaders = Table.CombineColumns(_Transposed,{"Column1", "Column2"},Combiner.CombineTextByDelimiter("||", QuoteStyle.None),"Merged"),
          _TransposedBack = Table.PromoteHeaders(Table.FromColumns(Table.ToRows(_MergedHeaders))),
          _Unpivoted = Table.UnpivotOtherColumns(_TransposedBack, {"||", "Pick Storage||Measures"}, "Attribute", "Value"),
          _Splitted = Table.SplitColumn(_Unpivoted, "Attribute", Splitter.SplitTextByDelimiter("||", QuoteStyle.Csv), {"Pick Storage", "Headers"}),
          _FilteredRows = Table.SelectRows(_Splitted, each ([#"||"] = "IM Delivery")),
          _Pivoted = Table.Pivot(_FilteredRows, List.Distinct(_FilteredRows[Headers]), "Headers", "Value"),
          _Renamed = Table.RenameColumns(_Pivoted,{{"||", "Status"}, {"Pick Storage||Measures", "Created Date"}}),
          _ChangedType = Table.TransformColumnTypes(_Renamed,{{"Status", type text}, {"Orders", type number}, {"Line Qty", type number}, {"Pending (IM)", type number}, {"Created Date", type date}}, "sk-SK"),
          _FilteredRows1 = Table.SelectRows(_ChangedType, each not List.ContainsAll({[Orders], [Line Qty], [#"Pending (IM)"]}, {null}) ),
          _SortedRows = Table.Sort(_FilteredRows1,{{"Created Date", Order.Ascending}})
        ][_SortedRows],

    Source = Folder.Files("c:\Downloads\PowerQueryForum\Justas4478\"),
    FilteredCSV = Table.SelectRows(Source, each [Extension] = ".csv"),
    ContentToTable = Table.TransformColumns(FilteredCSV, {{"Content", each Csv.Document(_,[Delimiter=",", Columns=14, Encoding=65001, QuoteStyle=QuoteStyle.None]), type table}}),
    RemovedOtherColumns = Table.SelectColumns(ContentToTable,{"Content", "Name"}),
    Ad_Transformed = Table.AddColumn(RemovedOtherColumns, "Transformed", each Table.AddColumn(fn_Transform([Content]), "SourceName", (x)=&amp;gt; [Name], type text) , type table),
    CombinedFiles = Table.Combine(Ad_Transformed[Transformed])

    
in
    CombinedFiles&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Sep 2024 08:57:10 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4163660#M136854</guid>
      <dc:creator>dufoq3</dc:creator>
      <dc:date>2024-09-21T08:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting multi header table in power query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4166758#M137075</link>
      <description>&lt;P&gt;Thank you for all the proposed solutions.&lt;BR /&gt;I wish I could understand them in detail to learn better but it might take too much time to explain.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2024 09:04:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4166758#M137075</guid>
      <dc:creator>Justas4478</dc:creator>
      <dc:date>2024-09-23T09:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting multi header table in power query</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4167190#M137096</link>
      <description>&lt;P&gt;The function I proposed explains the process step by step. There is no magic to this - you need to transform the source format step by step into something usable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only "fancy" part is the harvesting of the dangling headers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;LZ = List.Skip(List.Transform(List.Zip({Record.ToList(Source{0}),Record.ToList(Source{1})}),each Text.Combine(_,"|")),2)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use PowerQueryFormatter to make the code look easier to understand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;LZ
  = List.Skip(
    List.Transform(
      List.Zip({Record.ToList(Source{0}), Record.ToList(Source{1})}), 
      each Text.Combine(_, "|")
    ), 
    2
  )&lt;/LI-CODE&gt;
&lt;P&gt;We are treating the first two rows as if they were lists. We combine them via List.Zip, and then convert the result to pipe delimited strings.&amp;nbsp; Since the first two columns are ok we skip them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2024 12:03:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Sorting-multi-header-table-in-power-query/m-p/4167190#M137096</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-09-23T12:03:41Z</dc:date>
    </item>
  </channel>
</rss>

