<?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: Adjusting a SUMX expression slightly so it counts unique results rather than sums in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Adjusting-a-SUMX-expression-slightly-so-it-counts-unique-results/m-p/3193427#M115862</link>
    <description>&lt;P&gt;Try&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Num tenant references =
VAR _asOfDate = [As Of Date]
VAR _assetref =
    MAX ( Building[Asset Reference] )
VAR FilterTable =
    CALCULATETABLE (
        INDEX (
            1,
            Lease_Unit,
            ORDERBY ( Lease_Unit[Lease.Commencement Date], DESC ),
            PARTITIONBY ( Lease_Unit[Unit Reference] )
        ),
        OR (
            ISBLANK ( Lease_Unit[Unit.Unit Start Date] ),
            Lease_Unit[Unit.Unit Start Date] &amp;lt;= _asofdate
        )
            &amp;amp;&amp;amp; OR (
                ISBLANK ( Lease_Unit[Unit.Unit End Date] ),
                Lease_Unit[Unit.Unit End Date] &amp;gt;= _asofdate
            ),
        AND (
            Lease_Unit[Lease.Expiration Date] &amp;gt;= _asOfDate,
            Lease_Unit[Lease.Commencement Date] &amp;lt;= _asOfDate
        )
            || Lease_Unit[Lease.Lease Status] IN { "Holding Over", "Month-to-Month" },
        OR (
            Lease_Unit[Lease.Termination Date] &amp;gt;= _asOfDate,
            ISBLANK ( Lease_Unit[Lease.Termination Date] )
        )
    )
RETURN
    CALCULATE ( DISTINCTCOUNT ( 'Lease unit'[tenant reference] ), FilterTable )
&lt;/LI-CODE&gt;
&lt;P&gt;You should be able to just add this to a card visual and it will give you the total.&lt;/P&gt;</description>
    <pubDate>Tue, 18 Apr 2023 10:56:21 GMT</pubDate>
    <dc:creator>johnt75</dc:creator>
    <dc:date>2023-04-18T10:56:21Z</dc:date>
    <item>
      <title>Adjusting a SUMX expression slightly so it counts unique results rather than sums</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Adjusting-a-SUMX-expression-slightly-so-it-counts-unique-results/m-p/3193319#M115857</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;This is hopefully relatively straightforward. I've the following DAX expression that sums values from a table in my data model to provide results based on a set of filters/conditions:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Total Tenants 2 = 
VAR _asOfDate = [As Of Date]
VAR _assetref = MAX(Building[Asset Reference])

RETURN
VAR result = CALCULATE (
        SUMX (
            VALUES ( Lease_Uni[Unit Reference] ),
            SUMX (
                TOPN (
                    1,
                    FILTER (
                        Lease_Unit,
                        Lease_Unit[Unit Reference] = EARLIER ( Lease_Unit[Unit Reference] )
                    ),
                    Lease_Unit[Lease.Commencement Date]
                ),
                Lease_Unit[Leased Area]
            )
        ),
            
               OR(
                    ISBLANK ( Lease_Unit[Unit.Unit Start Date] ),
                    Lease_Unit[Unit.Unit Start Date] &amp;lt;= _asofdate
                )
                &amp;amp;&amp;amp; OR (
                    ISBLANK ( Lease_Unit[Unit.Unit End Date] ),
                    Lease_Unit[Unit.Unit End Date] &amp;gt;= _asofdate
                    )
           , 
        AND (
            Lease_Unit[Lease.Expiration Date] &amp;gt;= _asOfDate,
            Lease_Unit[Lease.Commencement Date] &amp;lt;= _asOfDate
        )
            || Lease_Unit[Lease.Lease Status] IN { "Holding Over", "Month-to-Month" },
        OR( 
            Lease_Unit[Lease.Termination Date] &amp;gt;= _asOfDate, 
        isblank(Lease_Unit[Lease.Termination Date])
        )
    )
RETURN
result&lt;/LI-CODE&gt;&lt;P&gt;1. How can I adapt the above so that it applies exactly the same filters that it is currently using to sum the results, but instead it counts the number of distinct results from a column in the table called [tenant reference]?&lt;/P&gt;&lt;P&gt;2. Is it correct that if I then use sumx, ([table], [measure] ) I can get the grand total so I can place this in a card visualisation?&lt;/P&gt;&lt;P&gt;I had begun with the approach below, but it is incorrect as it does not have all the filter logic from the above example. I'm not sure it is the right approach.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Total Tenants = 
VAR _table =
    FILTER (
        SUMMARIZECOLUMNS (
            Lease_Unit[Asset Reference],
            Lease_Unit[Lease.Tenant Reference]
        ),
        SUM(Lease_Unit[Leased Area]) &amp;gt; 0
    )
RETURN
    COUNTROWS ( _table )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 10:02:23 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Adjusting-a-SUMX-expression-slightly-so-it-counts-unique-results/m-p/3193319#M115857</guid>
      <dc:creator>julesdude</dc:creator>
      <dc:date>2023-04-18T10:02:23Z</dc:date>
    </item>
    <item>
      <title>Re: Adjusting a SUMX expression slightly so it counts unique results rather than sums</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Adjusting-a-SUMX-expression-slightly-so-it-counts-unique-results/m-p/3193427#M115862</link>
      <description>&lt;P&gt;Try&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Num tenant references =
VAR _asOfDate = [As Of Date]
VAR _assetref =
    MAX ( Building[Asset Reference] )
VAR FilterTable =
    CALCULATETABLE (
        INDEX (
            1,
            Lease_Unit,
            ORDERBY ( Lease_Unit[Lease.Commencement Date], DESC ),
            PARTITIONBY ( Lease_Unit[Unit Reference] )
        ),
        OR (
            ISBLANK ( Lease_Unit[Unit.Unit Start Date] ),
            Lease_Unit[Unit.Unit Start Date] &amp;lt;= _asofdate
        )
            &amp;amp;&amp;amp; OR (
                ISBLANK ( Lease_Unit[Unit.Unit End Date] ),
                Lease_Unit[Unit.Unit End Date] &amp;gt;= _asofdate
            ),
        AND (
            Lease_Unit[Lease.Expiration Date] &amp;gt;= _asOfDate,
            Lease_Unit[Lease.Commencement Date] &amp;lt;= _asOfDate
        )
            || Lease_Unit[Lease.Lease Status] IN { "Holding Over", "Month-to-Month" },
        OR (
            Lease_Unit[Lease.Termination Date] &amp;gt;= _asOfDate,
            ISBLANK ( Lease_Unit[Lease.Termination Date] )
        )
    )
RETURN
    CALCULATE ( DISTINCTCOUNT ( 'Lease unit'[tenant reference] ), FilterTable )
&lt;/LI-CODE&gt;
&lt;P&gt;You should be able to just add this to a card visual and it will give you the total.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 10:56:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Adjusting-a-SUMX-expression-slightly-so-it-counts-unique-results/m-p/3193427#M115862</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2023-04-18T10:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: Adjusting a SUMX expression slightly so it counts unique results rather than sums</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Adjusting-a-SUMX-expression-slightly-so-it-counts-unique-results/m-p/3193512#M115867</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="240987" data-lia-user-login="johnt75" class="lia-mention lia-mention-user"&gt;johnt75&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Superb. Thank you so much. I will test in more detail but that seems to have done the job perfectly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will definitely use this filter as a sort of 'template' measure whenever i need so I do not have to type out all the logic each time - I can assign it to that measure and reference it in any measure that needs it.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 11:46:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Adjusting-a-SUMX-expression-slightly-so-it-counts-unique-results/m-p/3193512#M115867</guid>
      <dc:creator>julesdude</dc:creator>
      <dc:date>2023-04-18T11:46:42Z</dc:date>
    </item>
    <item>
      <title>Re: Adjusting a SUMX expression slightly so it counts unique results rather than sums</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Adjusting-a-SUMX-expression-slightly-so-it-counts-unique-results/m-p/3194081#M115913</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="240987" data-lia-user-login="johnt75" class="lia-mention lia-mention-user"&gt;johnt75&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although at row level when I used the measure as a column it gave me the correct results, it didn't sum the grand total when I applied the measure to the card visual unfortunately.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 16:02:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Adjusting-a-SUMX-expression-slightly-so-it-counts-unique-results/m-p/3194081#M115913</guid>
      <dc:creator>julesdude</dc:creator>
      <dc:date>2023-04-18T16:02:04Z</dc:date>
    </item>
    <item>
      <title>Re: Adjusting a SUMX expression slightly so it counts unique results rather than sums</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Adjusting-a-SUMX-expression-slightly-so-it-counts-unique-results/m-p/3194083#M115914</link>
      <description>&lt;P&gt;Looks like you might need to do a SUMX over the values of whichever column is providing a unique ID for the row in your table or matrix visual&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 16:07:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Adjusting-a-SUMX-expression-slightly-so-it-counts-unique-results/m-p/3194083#M115914</guid>
      <dc:creator>johnt75</dc:creator>
      <dc:date>2023-04-18T16:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: Adjusting a SUMX expression slightly so it counts unique results rather than sums</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Adjusting-a-SUMX-expression-slightly-so-it-counts-unique-results/m-p/3194099#M115915</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="240987" data-lia-user-login="johnt75" class="lia-mention lia-mention-user"&gt;johnt75&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes. I wrote the following:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Total Tenants (Grand Total) =
SUMX(Lease_Unit, [Total Tenants]) //the measure that was your solution above&lt;/LI-CODE&gt;&lt;P&gt;However, this gives me more than the total by 14 additional tenants, so I am not sure my DAX is correct&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2023 16:14:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Adjusting-a-SUMX-expression-slightly-so-it-counts-unique-results/m-p/3194099#M115915</guid>
      <dc:creator>julesdude</dc:creator>
      <dc:date>2023-04-18T16:14:26Z</dc:date>
    </item>
  </channel>
</rss>

