<?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 Re: Create column with other column titles in Power Query</title>
    <link>https://community.fabric.microsoft.com/t5/Power-Query/Create-column-with-other-column-titles/m-p/2211475#M65521</link>
    <description>&lt;P&gt;Like I said, I'm a beginner, so I wasn't able to work with the M-Code samples.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But what I could read from it was enough to get the idea, and the I re-created the process via PowerQuery's click-the-GUI buttons &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I need to find a way to work with changing column titles in the source file(s)...&lt;/P&gt;</description>
    <pubDate>Mon, 29 Nov 2021 07:41:35 GMT</pubDate>
    <dc:creator>mckee</dc:creator>
    <dc:date>2021-11-29T07:41:35Z</dc:date>
    <item>
      <title>Create column with other column titles</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Create-column-with-other-column-titles/m-p/2205781#M65280</link>
      <description>&lt;P&gt;Hi all&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I'm new to PQ and M-Code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a new column. It should store the name of other columns, depending on the data inside these other columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Columns are oldest to newest (left to right) and contain quantities (currently stored as text, but I can switch to numeric, doesn't matter for my purpose)&lt;/LI&gt;&lt;LI&gt;I want to identify the newest (=most right) column which contains data (&amp;lt;&amp;gt; null and &amp;lt;&amp;gt; "" and &amp;lt;&amp;gt; 0) for each line&lt;/LI&gt;&lt;LI&gt;I want to transfer the name of the column found in step 2 into a new column for each line&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for any inputs in advance and feel free to ask back.&lt;BR /&gt;Marc&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 12:24:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Create-column-with-other-column-titles/m-p/2205781#M65280</guid>
      <dc:creator>mckee</dc:creator>
      <dc:date>2021-11-24T12:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create column with other column titles</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Create-column-with-other-column-titles/m-p/2206053#M65293</link>
      <description>&lt;P&gt;Try with this code. One way to sort out the issue&lt;/P&gt;&lt;P&gt;update: I sligthly change the code to meet your requirements. You are not ooking for the max value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlXSUTIDYnOlWJ1oJUsgyxiITcA8QwMg0wjENzSCCFiABECiSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"2020/1" = _t, #"2020/2" = _t, #"2020/3" = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Index"}, "Attribute", "Value"),
    #"Filtered Rows1" = Table.SelectRows(#"Unpivoted Other Columns", each [Value] &amp;lt;&amp;gt; null and [Value] &amp;lt;&amp;gt; ""),
    #"Grouped Rows" = Table.Group(#"Filtered Rows1", {"Index"}, {{"Max", each List.Max([Attribute]), type text}, {"Rows", each _, type table [Index=number, Attribute=text, Value=text]}}),
    #"Added Index for columns names" = Table.TransformColumns( #"Grouped Rows", {"Rows", each Table.AddIndexColumn(_, "I")}),
    #"Expanded Rows" = Table.ExpandTableColumn(#"Added Index for columns names", "Rows", {"Attribute", "I", "Value"}, {"Attribute", "I", "Value"}),
    #"Filtered Rows - hold max" = Table.SelectRows(#"Expanded Rows", each [Max] = [Attribute]),
    #"Merged Queries Added Index withfiltered rows" = Table.NestedJoin(#"Added Index", {"Index"}, #"Filtered Rows - hold max", {"Index"}, "Filtered Rows", JoinKind.LeftOuter),
    #"Expanded Filtered Rows" = Table.ExpandTableColumn(#"Merged Queries Added Index withfiltered rows", "Filtered Rows", {"I"}, {"I"}),
    #"Added Columns Names" = Table.AddColumn(#"Expanded Filtered Rows", "Names", each Table.ColumnNames(Source){[I]}),
    Cleanup = Table.RemoveColumns(#"Added Columns Names",{"Index", "I"})
in
    Cleanup&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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;</description>
      <pubDate>Wed, 24 Nov 2021 15:16:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Create-column-with-other-column-titles/m-p/2206053#M65293</guid>
      <dc:creator>latimeria</dc:creator>
      <dc:date>2021-11-24T15:16:16Z</dc:date>
    </item>
    <item>
      <title>Re: Create column with other column titles</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Create-column-with-other-column-titles/m-p/2206178#M65308</link>
      <description>&lt;P&gt;This is solid logic. I think you can streamline it by dropping your [Rows] column entirely in the Group By though. Your [Max] column should already have the latest month and you can skip straight to the merge.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 16:01:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Create-column-with-other-column-titles/m-p/2206178#M65308</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2021-11-24T16:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create column with other column titles</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Create-column-with-other-column-titles/m-p/2206301#M65317</link>
      <description>&lt;P&gt;That)s right.&lt;/P&gt;&lt;P&gt;Streamline version&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlXSUTIDYnOlWJ1oJUsgyxiITcA8QwMg0wjENzSCCFiABECiSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"2020/1" = _t, #"2020/2" = _t, #"2020/3" = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
        #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Added Index", {"Index"}, "Attribute", "Value"),
        #"Filtered Rows1" = Table.SelectRows(#"Unpivoted Other Columns", each [Value] &amp;lt;&amp;gt; null and [Value] &amp;lt;&amp;gt; ""),
        #"Grouped Rows" = Table.Group(#"Filtered Rows1", {"Index"}, {{"Max", each List.Max([Attribute]), type text}}),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Custom", each #"Grouped Rows"[Max] {List.PositionOf(#"Grouped Rows"[Index], [Index])}),
    Cleanup = Table.RemoveColumns(#"Added Custom",{"Index"})
in
    Cleanup&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 17:13:55 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Create-column-with-other-column-titles/m-p/2206301#M65317</guid>
      <dc:creator>latimeria</dc:creator>
      <dc:date>2021-11-24T17:13:55Z</dc:date>
    </item>
    <item>
      <title>Re: Create column with other column titles</title>
      <link>https://community.fabric.microsoft.com/t5/Power-Query/Create-column-with-other-column-titles/m-p/2211475#M65521</link>
      <description>&lt;P&gt;Like I said, I'm a beginner, so I wasn't able to work with the M-Code samples.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But what I could read from it was enough to get the idea, and the I re-created the process via PowerQuery's click-the-GUI buttons &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I need to find a way to work with changing column titles in the source file(s)...&lt;/P&gt;</description>
      <pubDate>Mon, 29 Nov 2021 07:41:35 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/Power-Query/Create-column-with-other-column-titles/m-p/2211475#M65521</guid>
      <dc:creator>mckee</dc:creator>
      <dc:date>2021-11-29T07:41:35Z</dc:date>
    </item>
  </channel>
</rss>

