<?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: [DAX] Help detecting the last matching substring from another column in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-detecting-the-last-matching-substring-from-another/m-p/2827085#M89916</link>
    <description>&lt;P&gt;Just found a temporal solution with excel... I want it with DAX tough...! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.google.com/spreadsheets/d/1MiCwtyh5SNBHbBjYNaLvSMUV2boR7Qog/edit?usp=sharing&amp;amp;ouid=117937705214354501008&amp;amp;rtpof=true&amp;amp;sd=true" target="_blank" rel="noopener"&gt;https://docs.google.com/spreadsheets/d/1MiCwtyh5SNBHbBjYNaLvSMUV2boR7Qog/edit?usp=sharing&amp;amp;ouid=117937705214354501008&amp;amp;rtpof=true&amp;amp;sd=true&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 08 Oct 2022 09:39:12 GMT</pubDate>
    <dc:creator>akakak</dc:creator>
    <dc:date>2022-10-08T09:39:12Z</dc:date>
    <item>
      <title>[DAX] Help detecting the last matching substring from another column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-detecting-the-last-matching-substring-from-another/m-p/2826565#M89878</link>
      <description>&lt;P&gt;Hello, I am having struggling with this dax question and I was wondering if someone faced a similar problem and could help me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I basically have 2 columns:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;The first one is an hierarchy that I create it with the "Path" function.&lt;/P&gt;&lt;P&gt;The second one are all the matching values from the column "Path" with another table of the model.&lt;/P&gt;&lt;P&gt;As you might know, the function Path returns the path ordered from upper to down (an ordered hierarchy). The second formula from the column "Matches_From_Another_Table", returns all the matching values of another table. But it obviously doesn't do it in an ordered manner (is not possible to order that table as in an organization chart, each team has their own path).&lt;/P&gt;&lt;P&gt;What I am looking for is a way to return the last value from the column "Path" matching some value of the column "Matches_From_Another_Table".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I leave attached the model as maybe the formula from "Matches_From_Another_Table" can be improved.&lt;/P&gt;&lt;P&gt;PS: Retrieving the maximum value is not valid because it id might be or not the biggest one.&lt;/P&gt;&lt;P&gt;PS2: The business case is that I have an&amp;nbsp;hierarchy of all the employees of the company. Also, I have another table specifiying the managers that create an area by themselves. So, I want to find the most inmediate employee's manager that creates an area, so I can assign them to an specific team.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The file:&lt;/P&gt;&lt;P&gt;&lt;A href="https://drive.google.com/file/d/1NI1KA7wl69hL2AuAHbBCMkg---MettbN/view?usp=sharing" target="_blank" rel="noopener"&gt;https://drive.google.com/file/d/1NI1KA7wl69hL2AuAHbBCMkg---MettbN/view?usp=sharing&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS3:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&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;</description>
      <pubDate>Sat, 08 Oct 2022 08:32:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-detecting-the-last-matching-substring-from-another/m-p/2826565#M89878</guid>
      <dc:creator>akakak</dc:creator>
      <dc:date>2022-10-08T08:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: [DAX] Help detecting the last matching substring from another column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-detecting-the-last-matching-substring-from-another/m-p/2827085#M89916</link>
      <description>&lt;P&gt;Just found a temporal solution with excel... I want it with DAX tough...! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.google.com/spreadsheets/d/1MiCwtyh5SNBHbBjYNaLvSMUV2boR7Qog/edit?usp=sharing&amp;amp;ouid=117937705214354501008&amp;amp;rtpof=true&amp;amp;sd=true" target="_blank" rel="noopener"&gt;https://docs.google.com/spreadsheets/d/1MiCwtyh5SNBHbBjYNaLvSMUV2boR7Qog/edit?usp=sharing&amp;amp;ouid=117937705214354501008&amp;amp;rtpof=true&amp;amp;sd=true&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Oct 2022 09:39:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-detecting-the-last-matching-substring-from-another/m-p/2827085#M89916</guid>
      <dc:creator>akakak</dc:creator>
      <dc:date>2022-10-08T09:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: [DAX] Help detecting the last matching substring from another column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-detecting-the-last-matching-substring-from-another/m-p/2830306#M90142</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="453325" data-lia-user-login="akakak" class="lia-mention lia-mention-user"&gt;akakak&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please try:&lt;/P&gt;
&lt;P&gt;First, create a duplicate table and split columns into rows:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Then add index column:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Here is the M code:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jZhbbiQhDEW3EvV3pIDNy/M3C5gVRNkJix/S4AudTrsszShV1LmFscF29efnjW/vN/mIHxSI3iL9CWH8e/v7bwzH8b/Hzvc/t6/3z1u5hIv++cZjfc3TBKnfoe+ru4SKYRATlRBVOO/6VOidvoepvX6PGtknBXs50WuRpNSSCu83ffJ74P6Saq1gGT+Z5dRaksPUSW1To1wHY0FrnhQcli1I480hX4d8QksSicmwLJdWArxGwpJin4NdpccjvNLYScsMpdSOLGz4VUWLUlFpbPgIxim3d3pLIh7h4iBMMQVj0+GUKIcNnlpgz4zK7RmFYrjeB4tajsmlBiMEmE05zFZkGOBYn3JYX02BPUdYOcw4BpIx4ylM4VEYoxF8mKocTG1C1djy+rjj4q6SFOR6Vyu14iA15OvgKQURV8dMi9KjEKuUeH2AFMPxj0yGbKd9BeHGyBzL9eKA6YzD7Gi4f589Bfep5dqyJ+QAD2Nby64Tr+CeNY9UZbhIKlHWmIzLDoHer9dQKJ4zCfCwgFu9rgXAMOO4t3L7lOUOsG9jS0ieGRcGWY3JcNWxxgXuNZZgGqszKoYKEJqVsA5ZOzdhocCerAPwMHSMuNao4CHlIEaBPqQLPKRllD7HOhe2C2S16tVZISvq/JIKic9FCzyl4ioGAI8WNHPw9FcAD2lhchms4CGtYnVOh3SBWyq1NEfeVUwDIxKD4SLIFnbKXGlMQRg62q2Wr7tDYGtG4pLzdWMGDLKWgycYALehuURXHAEe0hblOhjA1NhSk6PiAoNMSjUOF2QLU1kNsXpKLsD9tVU5shHDQ7rAUyqOag1MjW0hVSP83EYfosewjJWGPoc6lN8fNnNoAuu9lay8vYOs4A6yjKVdp0JguhLhYuVtPO/7agklJ2N3oIwCRBnl0IJ4shnA/cEYhJKRIMan12jloB+JKeU+Bzu0z8/WxyiRK8kCPL5ja3VVP4BbOnohz0ewYurDYbcVbtMRqn3liNHgO9ocYDCpsSu5ATycMFo0T/cL8EFqfSlhHwLc+5BaK0bemJ558tMSHYPzbTz6GqMIqdcUUyM4tmAs/XcjVPRsRGyuXgrgdiQTWzF4YcgSPRtCYv1Qg5wMcP/oxaPn8q1hgccaxjejp7EDeEqLdaAS1URJrZ53HSId2GsYX6+eagbwUWqkoUdp+im1yoeZFFT7Kimk2Op1awZMt3caieu6wALb10tdrKZnqwuFh0nF+tX2962soqetPB5YRpheVe1Lr47n130ksGOB1o+Je58ruPd54pQt35irWdrfVvP1Hw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [employee_id = _t, Date = _t, manager_id = _t, Path = _t, Matches_From_Another_Table = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"employee_id", Int64.Type}, {"Date", type datetime}, {"manager_id", Int64.Type}, {"Path", type text}, {"Matches_From_Another_Table", type text}}),
    #"Split Column by Delimiter" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type", {{"Path", Splitter.SplitTextByDelimiter("|", QuoteStyle.None), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Path"),
    #"Changed Type1" = Table.TransformColumnTypes(#"Split Column by Delimiter",{{"Path", Int64.Type}}),
    #"Split Column by Delimiter1" = Table.ExpandListColumn(Table.TransformColumns(#"Changed Type1", {{"Matches_From_Another_Table", Splitter.SplitTextByDelimiter("|", QuoteStyle.None), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Matches_From_Another_Table"),
    #"Changed Type2" = Table.TransformColumnTypes(#"Split Column by Delimiter1",{{"Matches_From_Another_Table", Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Changed Type2", each ([Path] &amp;lt;&amp;gt; null) and ([Matches_From_Another_Table] &amp;lt;&amp;gt; null)),
    #"Added Index" = Table.AddIndexColumn(#"Filtered Rows", "Index", 1, 1, Int64.Type)
in
    #"Added Index"&lt;/LI-CODE&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Then add a new column for your original table, here is the DAX:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Column =
VAR _a =
    SELECTCOLUMNS (
        FILTER ( 'Table (2)', [employee_id] = EARLIER ( 'Table'[employee_id] ) ),
        "a", [Matches_From_Another_Table]
    )
VAR _b =
    MAXX (
        FILTER (
            'Table (2)',
            [employee_id] = EARLIER ( 'Table'[employee_id] )
                &amp;amp;&amp;amp; [Path] IN _a
        ),
        [Index]
    )
RETURN
    CALCULATE ( MAX ( 'Table (2)'[Path] ), FILTER ( 'Table (2)', [Index] = _b ) )
&lt;/LI-CODE&gt;
&lt;P&gt;Final output:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P style="background: white; margin: 7.5pt 0in 0in 0in;"&gt;&lt;SPAN&gt;Best Regards,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="background: white; margin: 7.5pt 0in 0in 0in;"&gt;&lt;SPAN&gt;Jianbo Li&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="background: white; margin: 7.5pt 0in 0in 0in;"&gt;&lt;SPAN&gt;If this post&amp;nbsp;&lt;STRONG&gt;&lt;I&gt;helps&lt;/I&gt;&lt;/STRONG&gt;, then please consider&amp;nbsp;&lt;STRONG&gt;&lt;I&gt;Accept it as the solution&lt;/I&gt;&lt;/STRONG&gt;&amp;nbsp;to help the other members find it more quickly.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2022 08:29:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-detecting-the-last-matching-substring-from-another/m-p/2830306#M90142</guid>
      <dc:creator>v-jianboli-msft</dc:creator>
      <dc:date>2022-10-10T08:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: [DAX] Help detecting the last matching substring from another column</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-detecting-the-last-matching-substring-from-another/m-p/2830629#M90170</link>
      <description>&lt;P&gt;Holy cow that's super good and it works fast!&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;I needed to deliver it this monday so at the end wat I did was to create ficticial columns ( I created like 25 variables) seperating every number between commas. Every record was a number, then comparing the columns with the ones appearing in the path and retrieving only the first one to appear. Down below is not all the code, only the first variable. You can imagin how slow it was, so I'll substitute it straight away.&lt;/P&gt;&lt;P&gt;Thank you very much master!&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;VAR Path_01= VALUE(PATHITEM ( SUBSTITUTE ( Output_Salaries_Date_Max[Path]; "-"; "|" ); 1 ))&lt;/P&gt;&lt;P&gt;VAR Match_01= VALUE (PATHITEM ( SUBSTITUTE ( Output_Salaries_Date_Max[Matches_From_Another_Table]; "-"; "|" ); 1 ) )&lt;/P&gt;&lt;P&gt;VAR Reorder_01= VALUE(SWITCH (TRUE ();Match_01 = Path_01; Path_01;Match_02 = Path_01; Path_01;Match_03 = Path_01; Path_01;Match_04 = Path_01; Path_01;Match_05 = Path_01; Path_01;Match_06 = Path_01; Path_01;Match_07 = Path_01; Path_01;Match_08 = Path_01; Path_01;Match_09 = Path_01; Path_01;Match_10 = Path_01; Path_01;Match_11 = Path_01; Path_01;Match_12 = Path_01; Path_01;Match_13 = Path_01; Path_01;Match_14 = Path_01; Path_01;Match_15 = Path_01; Path_01;Match_16 = Path_01; Path_01;Match_17 = Path_01; Path_01;Match_18 = Path_01; Path_01;Match_19 = Path_01; Path_01;Match_20 = Path_01; Path_01;Match_21 = Path_01; Path_01;Match_22 = Path_01; Path_01;Match_23 = Path_01; Path_01;Match_24 = Path_01; Path_01;Match_25 = Path_01; Path_01;0) )&lt;/P&gt;&lt;P&gt;VAR Final_Calculation= SWITCH (TRUE ();Reorder_25 &amp;lt;&amp;gt; 0; Reorder_25;Reorder_24 &amp;lt;&amp;gt; 0; Reorder_24;Reorder_23 &amp;lt;&amp;gt; 0; Reorder_23;Reorder_22 &amp;lt;&amp;gt; 0; Reorder_22;Reorder_21 &amp;lt;&amp;gt; 0; Reorder_21;Reorder_20 &amp;lt;&amp;gt; 0; Reorder_20;Reorder_19 &amp;lt;&amp;gt; 0; Reorder_19;Reorder_18 &amp;lt;&amp;gt; 0; Reorder_18;Reorder_17 &amp;lt;&amp;gt; 0; Reorder_17;Reorder_16 &amp;lt;&amp;gt; 0; Reorder_16;Reorder_15 &amp;lt;&amp;gt; 0; Reorder_15;Reorder_14 &amp;lt;&amp;gt; 0; Reorder_14;Reorder_13 &amp;lt;&amp;gt; 0; Reorder_13;Reorder_12 &amp;lt;&amp;gt; 0; Reorder_12;Reorder_11 &amp;lt;&amp;gt; 0; Reorder_11;Reorder_10 &amp;lt;&amp;gt; 0; Reorder_10;Reorder_09 &amp;lt;&amp;gt; 0; Reorder_09;Reorder_08 &amp;lt;&amp;gt; 0; Reorder_08;Reorder_07 &amp;lt;&amp;gt; 0; Reorder_07;Reorder_06 &amp;lt;&amp;gt; 0; Reorder_06;Reorder_05 &amp;lt;&amp;gt; 0; Reorder_05;Reorder_04 &amp;lt;&amp;gt; 0; Reorder_04;Reorder_03 &amp;lt;&amp;gt; 0; Reorder_03;Reorder_02 &amp;lt;&amp;gt; 0; Reorder_02;Reorder_01 &amp;lt;&amp;gt; 0; Reorder_01;0)&lt;/P&gt;&lt;P&gt;RETURN&lt;/P&gt;&lt;P&gt;Final_Calculation&lt;/P&gt;</description>
      <pubDate>Mon, 10 Oct 2022 10:14:13 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-detecting-the-last-matching-substring-from-another/m-p/2830629#M90170</guid>
      <dc:creator>akakak</dc:creator>
      <dc:date>2022-10-10T10:14:13Z</dc:date>
    </item>
  </channel>
</rss>

