<?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 Aggregation Logic in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Aggregation-Logic/m-p/3349961#M125787</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table with primary keys CustomerID, YearMonth, and Product. This table will be filtered by a YearMonth slicer, and I want to create a measure that groups each CustomerID into one of 4 categories and then calculates DistinctCount(CustomerID) within each category to be displayed on a donut chart.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Categories&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;"A&amp;amp;B", "B&amp;amp;C", "A&amp;amp;C", "All 3"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Sample data&lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE border="1" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;CustomerID&lt;/TD&gt;&lt;TD&gt;YearMonth&lt;/TD&gt;&lt;TD&gt;Product&lt;/TD&gt;&lt;TD&gt;Flag&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5001&lt;/TD&gt;&lt;TD&gt;2022-01&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5001&lt;/TD&gt;&lt;TD&gt;2022-02&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR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gt;1) If 2022-01 through 2022-04 is selected, then Customer 5001 should be counted as "All 3", because each Product shows up at least once for this CustomerID within the time period.&amp;nbsp; Customer 5002 should be counted as "B&amp;amp;C".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) If 2022-03 through 2022-04 is selected, then Customer 5001 should be counted as "A&amp;amp;C". Customer 5002 should be counted as "B&amp;amp;C"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) If only 2022-01 is selected, neither customer should be counted in any of the 4 groups. Customer 5001 only has Product B, and Customer 5002 has none.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4) If only 2022-04 is selected, neither customer should be counted in any of the 4 groups. Customer 5001 has none, and Customer 5002 only has Product C. (We only want to consider records where Flag = Y).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas for a DAX query that can accomplish this? Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jul 2023 02:36:50 GMT</pubDate>
    <dc:creator>yelgrass</dc:creator>
    <dc:date>2023-07-26T02:36:50Z</dc:date>
    <item>
      <title>Aggregation Logic</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Aggregation-Logic/m-p/3349961#M125787</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table with primary keys CustomerID, YearMonth, and Product. This table will be filtered by a YearMonth slicer, and I want to create a measure that groups each CustomerID into one of 4 categories and then calculates DistinctCount(CustomerID) within each category to be displayed on a donut chart.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Categories&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;"A&amp;amp;B", "B&amp;amp;C", "A&amp;amp;C", "All 3"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&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D&gt;5002&lt;/TD&gt;&lt;TD&gt;2022-03&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5002&lt;/TD&gt;&lt;TD&gt;2022-04&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5002&lt;/TD&gt;&lt;TD&gt;2022-04&lt;/TD&gt;&lt;TD&gt;C&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Scenarios&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1) If 2022-01 through 2022-04 is selected, then Customer 5001 should be counted as "All 3", because each Product shows up at least once for this CustomerID within the time period.&amp;nbsp; Customer 5002 should be counted as "B&amp;amp;C".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) If 2022-03 through 2022-04 is selected, then Customer 5001 should be counted as "A&amp;amp;C". Customer 5002 should be counted as "B&amp;amp;C"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) If only 2022-01 is selected, neither customer should be counted in any of the 4 groups. Customer 5001 only has Product B, and Customer 5002 has none.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4) If only 2022-04 is selected, neither customer should be counted in any of the 4 groups. Customer 5001 has none, and Customer 5002 only has Product C. (We only want to consider records where Flag = Y).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas for a DAX query that can accomplish this? Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 02:36:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Aggregation-Logic/m-p/3349961#M125787</guid>
      <dc:creator>yelgrass</dc:creator>
      <dc:date>2023-07-26T02:36:50Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregation Logic</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Aggregation-Logic/m-p/3352961#M125918</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="594214" data-lia-user-login="yelgrass" class="lia-mention lia-mention-user"&gt;yelgrass&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;I'm not quite sure that my approach is optimal, but it seems to work.&lt;/P&gt;&lt;P&gt;The idea is to create such a measure and use it for aggregation:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;In plain text for convenience:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Measure = 
VAR CurrentID = MIN ( [CustomerID] )
VAR CurrentProducts = DISTINCT ( SELECTCOLUMNS ( FILTER ( 'Dataset', 'Dataset'[CustomerID] = CurrentID &amp;amp;&amp;amp; 'Dataset'[Flag] = "Y" ), "Product", [Product] ) )
RETURN 
SWITCH ( TRUE (),
         CONTAINS ( CurrentProducts, [Product], "A" ) &amp;amp;&amp;amp; CONTAINS ( CurrentProducts, [Product], "B" ) &amp;amp;&amp;amp; CONTAINS ( CurrentProducts, [Product], "C" ), "All 3",
         CONTAINS ( CurrentProducts, [Product], "A" ) &amp;amp;&amp;amp; CONTAINS ( CurrentProducts, [Product], "B" ), "A&amp;amp;B",
         CONTAINS ( CurrentProducts, [Product], "B" ) &amp;amp;&amp;amp; CONTAINS ( CurrentProducts, [Product], "C" ), "B&amp;amp;C",
         CONTAINS ( CurrentProducts, [Product], "A" ) &amp;amp;&amp;amp; CONTAINS ( CurrentProducts, [Product], "C" ), "A&amp;amp;C",
         BLANK() )&lt;/LI-CODE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;Best Regards, &lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;Alexander&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;&lt;A href="https://youtube.com/@powerbi-vlog" target="_blank"&gt;My YouTube vlog in English&lt;/A&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="2"&gt;&lt;A href="https://youtube.com/@pbi-vlog" target="_blank"&gt;My YouTube vlog in Russian&lt;/A&gt;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 10:00:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Aggregation-Logic/m-p/3352961#M125918</guid>
      <dc:creator>barritown</dc:creator>
      <dc:date>2023-07-27T10:00:21Z</dc:date>
    </item>
  </channel>
</rss>

