<?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: Summarize Function in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-Function/m-p/1797822#M37873</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="229849" data-lia-user-login="91asma2" class="lia-mention lia-mention-user"&gt;91asma2&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below are some ideas for improving performance. Would also be useful to see data model diagram or get a copy of pbix with sanitised data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The principles I have applied are:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;In &lt;STRONG&gt;User with &amp;gt; 1 Disorder&lt;/STRONG&gt;, &lt;A href="https://www.sqlbi.com/articles/best-practices-using-summarize-and-addcolumns/" target="_blank" rel="noopener"&gt;Best not to add extension columns within SUMMARIZE&lt;/A&gt;. In this case, SUMMARIZE ( Assessment, Assessment[User ID] ) is equivalent to VALUES ( Assessment[User ID] ), so simplified to that.&lt;/LI&gt;
&lt;LI&gt;In &lt;STRONG&gt;Disorders Ct&lt;/STRONG&gt;, it's more efficient to filter columns, not the entire Assessment table. To retain the existing filter context (which FILTER ( Assessment,...) would have done), wrapped the filter arguments of CALCULATE in KEEPFILTERS.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;User with &amp;gt; 1 Disorder = 
COUNTROWS (
    FILTER (
        VALUES ( Assessment[User ID] ),
        [Disorders Ct] &amp;gt; 1
    )
)&lt;/LI-CODE&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;LI-CODE lang="markup"&gt;Disorders Ct =
CALCULATE (
    DISTINCTCOUNT ( Assessment[assessment_id] ),
    KEEPFILTERS ( Assessment[Assess Score] = 1 ),
    KEEPFILTERS ( Assessment[Assess Category]
        IN { "ADDICTION", "ADHD", "APNEA", " DEPRESSION", "GEN_ANX", "PTSD", "SOC_ANX" } )
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One other possible tweak which I didn't apply is to use SUMX/SUMMARIZE in place of DISTINCTCOUNT, which can help in certain data models. &lt;A href="https://www.sqlbi.com/articles/analyzing-distinctcount-performance-in-dax/" target="_blank" rel="noopener"&gt;See here&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would be interested to know if this improves performance at all, otherwise might have to take a further look.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Owen&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 21 Apr 2021 13:43:43 GMT</pubDate>
    <dc:creator>OwenAuger</dc:creator>
    <dc:date>2021-04-21T13:43:43Z</dc:date>
    <item>
      <title>Summarize Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-Function/m-p/1797710#M37872</link>
      <description />
      <pubDate>Wed, 23 Jun 2021 19:09:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-Function/m-p/1797710#M37872</guid>
      <dc:creator>91asma2</dc:creator>
      <dc:date>2021-06-23T19:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-Function/m-p/1797822#M37873</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="229849" data-lia-user-login="91asma2" class="lia-mention lia-mention-user"&gt;91asma2&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below are some ideas for improving performance. Would also be useful to see data model diagram or get a copy of pbix with sanitised data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The principles I have applied are:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;In &lt;STRONG&gt;User with &amp;gt; 1 Disorder&lt;/STRONG&gt;, &lt;A href="https://www.sqlbi.com/articles/best-practices-using-summarize-and-addcolumns/" target="_blank" rel="noopener"&gt;Best not to add extension columns within SUMMARIZE&lt;/A&gt;. In this case, SUMMARIZE ( Assessment, Assessment[User ID] ) is equivalent to VALUES ( Assessment[User ID] ), so simplified to that.&lt;/LI&gt;
&lt;LI&gt;In &lt;STRONG&gt;Disorders Ct&lt;/STRONG&gt;, it's more efficient to filter columns, not the entire Assessment table. To retain the existing filter context (which FILTER ( Assessment,...) would have done), wrapped the filter arguments of CALCULATE in KEEPFILTERS.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;User with &amp;gt; 1 Disorder = 
COUNTROWS (
    FILTER (
        VALUES ( Assessment[User ID] ),
        [Disorders Ct] &amp;gt; 1
    )
)&lt;/LI-CODE&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;LI-CODE lang="markup"&gt;Disorders Ct =
CALCULATE (
    DISTINCTCOUNT ( Assessment[assessment_id] ),
    KEEPFILTERS ( Assessment[Assess Score] = 1 ),
    KEEPFILTERS ( Assessment[Assess Category]
        IN { "ADDICTION", "ADHD", "APNEA", " DEPRESSION", "GEN_ANX", "PTSD", "SOC_ANX" } )
)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One other possible tweak which I didn't apply is to use SUMX/SUMMARIZE in place of DISTINCTCOUNT, which can help in certain data models. &lt;A href="https://www.sqlbi.com/articles/analyzing-distinctcount-performance-in-dax/" target="_blank" rel="noopener"&gt;See here&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would be interested to know if this improves performance at all, otherwise might have to take a further look.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Owen&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 13:43:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-Function/m-p/1797822#M37873</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2021-04-21T13:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-Function/m-p/1798134#M37881</link>
      <description>&lt;P&gt;Thank you so much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Jun 2021 19:10:29 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-Function/m-p/1798134#M37881</guid>
      <dc:creator>91asma2</dc:creator>
      <dc:date>2021-06-23T19:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-Function/m-p/1798284#M37892</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="229849" data-lia-user-login="91asma2" class="lia-mention lia-mention-user"&gt;91asma2&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Of course you're getting BLANKS. That's obvious when you look at your measure and think for a sec. You're trying to filter AssesmentID's using the [Disorders Ct] measure. It's obvious that for any one particular assessment the measure will return either 0 or 1. So the filter removes all assessments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You should not have changed the measure&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="6799" data-lia-user-login="OwenAuger" class="lia-mention lia-mention-user"&gt;OwenAuger&lt;/a&gt;&amp;nbsp;gave you because if you want to count the USERS where [Disorders Ct] &amp;gt; 1, then it makes no sense whatsoever to filter assessments by the mentioned measure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By the way, one more way to write the measure is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;Disorders Ct =
var Score_ = 
    SELECTCOLUMNS(
        {1},
        "@Score", [Value]
    )
var Category_ = {
        "ADDICTION",
        "ADHD",
        "APNEA",
        " DEPRESSION",
        "GEN_ANX",
        "PTSD",
        "SOC_ANX"
    }
var Filter_ =
    CROSSJOIN(
        Score_,
        Category_
    )
var Result =
    CALCULATE(
        DISTINCTCOUNT( Assessment[assessment_id] ),
        // If you want to obey any filters that are
        // already present on either [Assses Score]
        // or [Assess Category] you have to wrap
        // the TREATAS in KEEPFILTERS. If in doubt,
        // just use this measure first and then the
        // version with:
        //
        //KEEPFILTERS(
        //    TREATAS(
        //        Filter_,
        //        Assessment[Assess Score],
        //        Assessment[Assess Category]
        //    )
        //)
        //
        // KEEPFILTERS enables you to join filters
        // in the measure and coming from outside
        // in an AND operation instead of overwriting
        // which is the usual semantics of filters in
        // CALCULATE.
        TREATAS(
            Filter_,
            Assessment[Assess Score],
            Assessment[Assess Category]
        )
    )
return
    Result&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 21 Apr 2021 17:40:19 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-Function/m-p/1798284#M37892</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-04-21T17:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: Summarize Function</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-Function/m-p/1798520#M37917</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="229849" data-lia-user-login="91asma2" class="lia-mention lia-mention-user"&gt;91asma2&lt;/a&gt;, I did tell you exactly why you get blanks. It's now up to you, I guess, what you want to do with this knowledge. If you still don't understand why you're getting blanks, then you have no choice but to revise/learn how context transition works in conjunction with CALCULATE in iterators like SUMX or FILTER. I guess there's no way around this, unfortunately.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can start with this:&amp;nbsp;&lt;A href="https://www.sqlbi.com/blog/marco/2010/01/03/how-calculate-works-in-dax/" target="_blank"&gt;How CALCULATE works in DAX - SQLBI&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And please do not fall into the trap as many others do when they think that you can write correct DAX without learning the theory behind it. &lt;STRONG&gt;DAX can't be learned from examples&lt;/STRONG&gt;. You have to learn the theory. Sorry.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Apr 2021 20:28:48 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Summarize-Function/m-p/1798520#M37917</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2021-04-21T20:28:48Z</dc:date>
    </item>
  </channel>
</rss>

