<?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: Conditional filter within calculate function? in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2379060#M61412</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="39298" data-lia-user-login="AlexisOlson" class="lia-mention lia-mention-user"&gt;AlexisOlson&lt;/a&gt;&amp;nbsp;This is exactly what I was looking for! Thank you so much!&lt;/P&gt;</description>
    <pubDate>Mon, 07 Mar 2022 15:32:57 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-03-07T15:32:57Z</dc:date>
    <item>
      <title>Conditional filter within calculate function?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2375554#M61156</link>
      <description>&lt;DIV&gt;&lt;SPAN&gt;I am trying to create a measure that has a conditional filter within the Calculate function.&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Here is a stripped down version of what I am trying to do.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;PersonaPortfolio = a table that is filtered down based on the USERPRINCIPALNAME. It's just a two column table, &lt;STRONG&gt;User&lt;/STRONG&gt; and &lt;STRONG&gt;Portfolio.&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;FilterPortfolio = I am filtering the fact table where values in the Portfolio field exist in the PersonaPortfolio table.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This works as long as there is the 'Persona Choices (Portfolio)' table is not empty.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;My problem is that I want to ignore any filters if the&amp;nbsp;'Persona Choices (Portfolio)' is empty, but I get the error "The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value" whenever I try to put an if statement into the filter portion of my calculate function.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;img /&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Is there any way to do handle this without putting that if statement in the filter portion of the calculate function?&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 04 Mar 2022 17:42:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2375554#M61156</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-04T17:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional filter within calculate function?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2375589#M61160</link>
      <description>&lt;P&gt;Hello there&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;! Does this work for you?&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Test =
VAR PersonaPortfolio =
    CALCULATETABLE (
        VALUES ( 'Persona Choices (Portfolio)'[Portfolio] ),
        'Persona Choices (Portfolio)'[User] = USERPRINCIPALNAME ()
    )
RETURN
    SWITCH (
        TRUE (),
        ISEMPTY ( PersonaPortfolio ),
            CALCULATE (
                [Delta-P],
                FILTER ( fact_DeltaP, NOT ( fact_DeltaP[Portfolio] IN PersonaPortfolio ) )
            ),
        CALCULATE (
            [Delta-P],
            FILTER ( fact_DeltaP, fact_DeltaP[Portfolio] IN PersonaPortfolio )
        )
    )&lt;/LI-CODE&gt;
&lt;P&gt;Hope this answer solves your problem!&lt;BR /&gt;If you need any additional help please &lt;SPAN&gt;@&lt;/SPAN&gt; me in your reply.&lt;BR /&gt;If my reply provided you with a solution, please consider marking it as a solution &lt;span class="lia-unicode-emoji" title=":heavy_check_mark:"&gt;✔️&lt;/span&gt; or giving it a kudoe &lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://www.linkedin.com/in/gon%C3%A7alo-costa-b32253159" target="_blank"&gt;You can also check out my LinkedIn!&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;Gonçalo Geraldes&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 18:03:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2375589#M61160</guid>
      <dc:creator>goncalogeraldes</dc:creator>
      <dc:date>2022-03-04T18:03:04Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional filter within calculate function?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2375711#M61172</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="301004" data-lia-user-login="goncalogeraldes" class="lia-mention lia-mention-user"&gt;goncalogeraldes&lt;/a&gt;&amp;nbsp;This does get rid of that error. Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The next level of complexity would be having 2 conditions within that calculate function. Is that a possibility using the same switch function logic?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 20:05:40 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2375711#M61172</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-04T20:05:40Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional filter within calculate function?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2375804#M61176</link>
      <description>&lt;P&gt;The IF function can't output tables, only single values, but you could rewrite this more like&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;SWITCH (
    TRUE (),
        ISEMPTY ( A ) &amp;amp;&amp;amp;     ISEMPTY ( B ), CALCULATE ( [Delta-P], IgnoreA, IgnoreB ),
        ISEMPTY ( A ) &amp;amp;&amp;amp; NOT ISEMPTY ( B ), CALCULATE ( [Delta-P], IgnoreA, FilterB ),
    NOT ISEMPTY ( A ) &amp;amp;&amp;amp;     ISEMPTY ( B ), CALCULATE ( [Delta-P], FilterA, IgnoreB ),
    NOT ISEMPTY ( A ) &amp;amp;&amp;amp; NOT ISEMPTY ( B ), CALCULATE ( [Delta-P], FilterA, FilterB )
)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 04 Mar 2022 21:04:25 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2375804#M61176</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2022-03-04T21:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional filter within calculate function?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2375878#M61188</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="39298" data-lia-user-login="AlexisOlson" class="lia-mention lia-mention-user"&gt;AlexisOlson&lt;/a&gt;&amp;nbsp;This worked, thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 4 different tables it is referencing, A,B,C, and D. Your example is showing A and B. Due to this, I needed to have 16 of those scenarios listed out in my code. I'm afraid of it getting out of control if I need to add any more tables. Are you familiar with a more concise way to handle this or is the code you provided the only solution?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 22:23:02 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2375878#M61188</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-04T22:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional filter within calculate function?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2375905#M61190</link>
      <description>&lt;P&gt;Yeah, I think you can refactor it to combine FilterA and IgnoreA like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="php"&gt;Test =
VAR A = CALCULATE ( [...] )
VAR B = CALCULATE ( [...] )
VAR C = CALCULATE ( [...] )
VAR D = CALCULATE ( [...] )
VAR FilterA = FILTER ( fact, IF ( ISEMPTY ( A ), NOT fact[A] IN A, fact[A] IN A ) )
VAR FilterB = FILTER ( fact, IF ( ISEMPTY ( B ), NOT fact[B] IN B, fact[B] IN B ) )
VAR FilterC = FILTER ( fact, IF ( ISEMPTY ( C ), NOT fact[C] IN C, fact[C] IN C ) )
VAR FilterD = FILTER ( fact, IF ( ISEMPTY ( D ), NOT fact[D] IN D, fact[D] IN D ) )
RETURN
    CALCULATE ( [Delta-P], FilterA, FilterB, FilterC, FilterD )&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 04 Mar 2022 22:50:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2375905#M61190</guid>
      <dc:creator>AlexisOlson</dc:creator>
      <dc:date>2022-03-04T22:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional filter within calculate function?</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2379060#M61412</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="39298" data-lia-user-login="AlexisOlson" class="lia-mention lia-mention-user"&gt;AlexisOlson&lt;/a&gt;&amp;nbsp;This is exactly what I was looking for! Thank you so much!&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 15:32:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Conditional-filter-within-calculate-function/m-p/2379060#M61412</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-03-07T15:32:57Z</dc:date>
    </item>
  </channel>
</rss>

