<?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 Extract Text based on conditions in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extract-Text-based-on-conditions/m-p/4033302#M159657</link>
    <description>&lt;P&gt;Can someone please help me write this Visual Basic function in DAX, I need to create a new column to extract this text from an exisitng column in the Dataset.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Function GetDescription(TEXT3 As String, CLASSNAME As String)&lt;BR /&gt;Dim Description As String&lt;/P&gt;&lt;P&gt;Description = ""&lt;/P&gt;&lt;P&gt;If FindWord(TEXT3, 1) = "*GMP*" Then&lt;BR /&gt;If InStr(1, FindWord(TEXT3, 2), "AGR") &amp;gt; 0 Then&lt;BR /&gt;If IsNumeric(FindWord(TEXT3, 3)) Then&lt;BR /&gt;Description = Mid(TEXT3, InStr(1, TEXT3, FindWord(TEXT3, 3)) + Len(FindWord(TEXT3, 3)), Len(TEXT3) - InStr(1, TEXT3, FindWord(TEXT3, 3)) + Len(FindWord(TEXT3, 3)))&lt;BR /&gt;&lt;BR /&gt;Else&lt;BR /&gt;Description = Mid(TEXT3, InStr(1, TEXT3, FindWord(TEXT3, 2)) + Len(FindWord(TEXT3, 2)), Len(TEXT3) - InStr(1, TEXT3, FindWord(TEXT3, 2)) + Len(FindWord(TEXT3, 2)))&lt;BR /&gt;End If&lt;BR /&gt;ElseIf InStr(1, FindWord(TEXT3, 2), "ESA") &amp;gt; 0 Then&lt;BR /&gt;Description = Mid(TEXT3, InStr(1, TEXT3, FindWord(TEXT3, 2)) + Len(FindWord(TEXT3, 2)), Len(TEXT3) - InStr(1, TEXT3, FindWord(TEXT3, 2)) + Len(FindWord(TEXT3, 2)))&lt;BR /&gt;Else&lt;BR /&gt;Description = Mid(TEXT3, InStr(1, TEXT3, FindWord(TEXT3, 1)) + Len(FindWord(TEXT3, 1)), Len(TEXT3) - InStr(1, TEXT3, FindWord(TEXT3, 1)) + Len(FindWord(TEXT3, 1)))&lt;BR /&gt;End If&lt;BR /&gt;Else&lt;BR /&gt;Description = TEXT3&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;If InStr(1, Description, " - " &amp;amp; CLASSNAME) &amp;gt; 0 Then&lt;BR /&gt;GetDescription = Mid(Description, 1, InStr(1, Description, " - " &amp;amp; CLASSNAME) - 1)&lt;BR /&gt;Else&lt;BR /&gt;GetDescription = Description&lt;BR /&gt;End If&lt;BR /&gt;End Function&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jul 2024 00:03:48 GMT</pubDate>
    <dc:creator>asadnaeem</dc:creator>
    <dc:date>2024-07-10T00:03:48Z</dc:date>
    <item>
      <title>Extract Text based on conditions</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extract-Text-based-on-conditions/m-p/4033302#M159657</link>
      <description>&lt;P&gt;Can someone please help me write this Visual Basic function in DAX, I need to create a new column to extract this text from an exisitng column in the Dataset.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Function GetDescription(TEXT3 As String, CLASSNAME As String)&lt;BR /&gt;Dim Description As String&lt;/P&gt;&lt;P&gt;Description = ""&lt;/P&gt;&lt;P&gt;If FindWord(TEXT3, 1) = "*GMP*" Then&lt;BR /&gt;If InStr(1, FindWord(TEXT3, 2), "AGR") &amp;gt; 0 Then&lt;BR /&gt;If IsNumeric(FindWord(TEXT3, 3)) Then&lt;BR /&gt;Description = Mid(TEXT3, InStr(1, TEXT3, FindWord(TEXT3, 3)) + Len(FindWord(TEXT3, 3)), Len(TEXT3) - InStr(1, TEXT3, FindWord(TEXT3, 3)) + Len(FindWord(TEXT3, 3)))&lt;BR /&gt;&lt;BR /&gt;Else&lt;BR /&gt;Description = Mid(TEXT3, InStr(1, TEXT3, FindWord(TEXT3, 2)) + Len(FindWord(TEXT3, 2)), Len(TEXT3) - InStr(1, TEXT3, FindWord(TEXT3, 2)) + Len(FindWord(TEXT3, 2)))&lt;BR /&gt;End If&lt;BR /&gt;ElseIf InStr(1, FindWord(TEXT3, 2), "ESA") &amp;gt; 0 Then&lt;BR /&gt;Description = Mid(TEXT3, InStr(1, TEXT3, FindWord(TEXT3, 2)) + Len(FindWord(TEXT3, 2)), Len(TEXT3) - InStr(1, TEXT3, FindWord(TEXT3, 2)) + Len(FindWord(TEXT3, 2)))&lt;BR /&gt;Else&lt;BR /&gt;Description = Mid(TEXT3, InStr(1, TEXT3, FindWord(TEXT3, 1)) + Len(FindWord(TEXT3, 1)), Len(TEXT3) - InStr(1, TEXT3, FindWord(TEXT3, 1)) + Len(FindWord(TEXT3, 1)))&lt;BR /&gt;End If&lt;BR /&gt;Else&lt;BR /&gt;Description = TEXT3&lt;BR /&gt;End If&lt;/P&gt;&lt;P&gt;If InStr(1, Description, " - " &amp;amp; CLASSNAME) &amp;gt; 0 Then&lt;BR /&gt;GetDescription = Mid(Description, 1, InStr(1, Description, " - " &amp;amp; CLASSNAME) - 1)&lt;BR /&gt;Else&lt;BR /&gt;GetDescription = Description&lt;BR /&gt;End If&lt;BR /&gt;End Function&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 00:03:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extract-Text-based-on-conditions/m-p/4033302#M159657</guid>
      <dc:creator>asadnaeem</dc:creator>
      <dc:date>2024-07-10T00:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: Extract Text based on conditions</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extract-Text-based-on-conditions/m-p/4033346#M159665</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="772937" data-lia-user-login="asadnaeem" class="lia-mention lia-mention-user"&gt;asadnaeem&lt;/a&gt;&amp;nbsp;,&lt;BR /&gt;&lt;BR /&gt;Based on the Visual Basic function you provided, it appears that the function looks for specific keywords in the TEXT3 string, it handles different string operations depending on the presence of certain content, and outputs either a TEXT3 substring or the entire string.&lt;BR /&gt;But without sample data it may be more difficult to correctly modify the Visual Basic function to a DAX, I tried to make the modification, if that DAX is not correct, could you please provide me with your sample data and expected results.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;GetDescription = 
VAR TEXT3 = YourTable[YourColumn]
VAR CLASSNAME = YourClassNameColumn
VAR Word1Position = IFERROR(SEARCH("*GMP*", TEXT3), -1)
VAR Word2Segment = MID(TEXT3, Word1Position + 5, LEN(TEXT3))
VAR AgrPosition = IFERROR(SEARCH("AGR", Word2Segment), -1)
VAR Description = 
    SWITCH(
        TRUE(),
        Word1Position &amp;gt; -1 &amp;amp;&amp;amp; AgrPosition &amp;gt; -1, MID(TEXT3, AgrPosition, LEN(TEXT3) - AgrPosition),
        // Add more cases as necessary
        TEXT3
    )
VAR ClassNamePos = SEARCH(" - " &amp;amp; CLASSNAME, Description, 1, LEN(Description))  // Handle error if necessary

RETURN
    IF(ClassNamePos &amp;gt; 0, MID(Description, 1, ClassNamePos - 1), Description)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;BR /&gt;Best Regards,&lt;BR /&gt;Dino Tao&lt;BR /&gt;If this post &lt;EM&gt;&lt;STRONG&gt;helps&lt;/STRONG&gt;&lt;/EM&gt;, then please consider &lt;EM&gt;&lt;STRONG&gt;Accept it as the solution&lt;/STRONG&gt;&lt;/EM&gt; to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2024 01:17:17 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Extract-Text-based-on-conditions/m-p/4033346#M159665</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-07-10T01:17:17Z</dc:date>
    </item>
  </channel>
</rss>

