<?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: Sum result from a grouping by category in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/975805#M11785</link>
    <description>Please mark the answer that's the solution as the solution via the 'Accept as Solution' button below the post.&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D</description>
    <pubDate>Mon, 16 Mar 2020 10:05:08 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2020-03-16T10:05:08Z</dc:date>
    <item>
      <title>Sum result from a grouping by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/960825#M11221</link>
      <description>&lt;P&gt;I have a hierarchy Category &amp;gt; Product. A product can be once, twice, etc. or zero time in a category.&lt;/P&gt;&lt;P&gt;Like that:&lt;/P&gt;&lt;P&gt;- Category 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; - Product 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; - Product 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; - Product 2&lt;/P&gt;&lt;P&gt;- Category 2&lt;/P&gt;&lt;P&gt;&amp;nbsp; - Product 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; - Product 3&lt;/P&gt;&lt;P&gt;- Category 3&lt;/P&gt;&lt;P&gt;&amp;nbsp; - Product 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; - Product 3&lt;/P&gt;&lt;P&gt;&amp;nbsp; - Product 3&lt;/P&gt;&lt;P&gt;&amp;nbsp; - ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to know if a Product is in several Category. I wanted to distinctcount products by category then sum the result.&lt;/P&gt;&lt;P&gt;But it seems like I do not know how to use GROUPBY()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know how to handle it?&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 16:29:44 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/960825#M11221</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-05T16:29:44Z</dc:date>
    </item>
    <item>
      <title>Re: Sum result from a grouping by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/960859#M11223</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try a measure&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure = CALCULATE(DISTINCTCOUNT(Table[Category]), ALLEXCEPT(Table, Table[Product]))&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 05 Mar 2020 16:50:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/960859#M11223</guid>
      <dc:creator>az38</dc:creator>
      <dc:date>2020-03-05T16:50:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sum result from a grouping by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/960881#M11224</link>
      <description>&lt;P&gt;Thanks for this answer!&lt;/P&gt;&lt;P&gt;What I have found (because it is in DirectQuery and difficult to see every lines) is that each Product is present in each Category but with a unit of 0 if they are not present.&lt;/P&gt;&lt;P&gt;How could I add a filter on object[unit] &amp;gt; 0? (it does not work like that)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 05 Mar 2020 17:00:58 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/960881#M11224</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-05T17:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Sum result from a grouping by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/960885#M11225</link>
      <description>&lt;P&gt;Anonymous&lt;/LI-USER&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure = CALCULATE(DISTINCTCOUNT(Table[Category]), ALLEXCEPT(Table, Table[Product]), Table[Unit]&amp;gt;0)&lt;/LI-CODE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Measure = CALCULATE(DISTINCTCOUNT(Table[Category]), FILTER(ALL(Table), Table[Product]=SELECTEDVALUE(Table[Product]) &amp;amp;&amp;amp; Table[Unit]&amp;gt;0))&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 05 Mar 2020 17:06:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/960885#M11225</guid>
      <dc:creator>az38</dc:creator>
      <dc:date>2020-03-05T17:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: Sum result from a grouping by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/963309#M11363</link>
      <description>&lt;P&gt;If a product can be in several categories, then there must be a bridge table that associates a product to categories. Say that you've got this setup: Product [1:*] ProductCategory [*:1] Category. You say that each product is associated with every category but there's a field in ProductCategory (say its name is Present) that has 1 in it when the category applies to the product and 0 if not. You want to know for each product if it's in at least 2 categories. So this would be a calculated column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the formula:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;[In At Least 2 Categories] = // calc column
sumx(
    relatedtable( ProductCategory ),
    ProductCategory[Present] * 1
) &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;If you want a measure that will work only for individual products...&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;[In At Least 2 Categories] =
var __oneProdVisible = HASONEVALUE( Product[ProductId] )
var __result =
	SUMX(
		ProductCategory,
		// If the type of the field below is int
		// then you don't have to multiply by 1,
		// but if it's boolean, you have to.
		ProductCategory[Unit] * 1
	) &amp;gt; 1
return
	if( __oneProdVisible, __result )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best&lt;/P&gt;
&lt;P&gt;D&lt;/P&gt;</description>
      <pubDate>Sat, 07 Mar 2020 22:36:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/963309#M11363</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-07T22:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Sum result from a grouping by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/964186#M11400</link>
      <description>&lt;P&gt;Thank you for all these answers!&lt;/P&gt;&lt;P&gt;How could I get the total number of multi-category products.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because, when I display the product column and the DAX mesure, I can know if a product is multi-category or not.&lt;/P&gt;&lt;P&gt;But when I put it in a card visual, I only get 1.&lt;/P&gt;&lt;P&gt;Is it possible to sum the distinct count of product by category for each product in a measure?&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 08:39:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/964186#M11400</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-09T08:39:33Z</dc:date>
    </item>
    <item>
      <title>Re: Sum result from a grouping by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/964651#M11412</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;// For each product, this measure returns
// the total number of categories the product
// belongs to (regardless of how many categories
// are visible). Bear in mind that the bridge table
// ProductCategory should be hidden and slicing
// cannot be done on it. It's only an auxiliary
// table that associates products with their
// categories.
[# Total Categories] =
var __oneProdVisible = HASONEVALUE( Product[ProductId] )
var __result =
	CALCULATE(
		SUMX(
			ProductCategory,
			// If the type of the field below is int
			// then you don't have to multiply by 1,
			// but if it's boolean, you have to.
			ProductCategory[Unit] * 1
		),
		ALL( Category )
	)
return
	if( __oneProdVisible, __result )

// This tells you how many products in the current
// context are multi-cat products. If you want to
// see 0 instead of BLANK, you can add 0 to
// the COUNTROWS function.
[# Multi-Cat Products] =
	COUNTROWS(
		FILTER(
			VALUES( Product[ProductId] ),
			[# Total Categories] &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;Best&lt;/P&gt;
&lt;P&gt;D&lt;/P&gt;</description>
      <pubDate>Mon, 09 Mar 2020 12:49:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/964651#M11412</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-09T12:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Sum result from a grouping by category</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/975805#M11785</link>
      <description>Please mark the answer that's the solution as the solution via the 'Accept as Solution' button below the post.&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;Best&lt;BR /&gt;D</description>
      <pubDate>Mon, 16 Mar 2020 10:05:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Sum-result-from-a-grouping-by-category/m-p/975805#M11785</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-03-16T10:05:08Z</dc:date>
    </item>
  </channel>
</rss>

