<?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 Distribution of one measure by another - pbix and dax.do code provided in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Distribution-of-one-measure-by-another-pbix-and-dax-do-code/m-p/4239886#M167801</link>
    <description>&lt;P&gt;I am using the Contoso db (dax.do).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;There is a sales table, which is a fact table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are also customer, product, and order dimension tables.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I want to see the distribution of the count of distinct product keys by order number. Do most orders have just one product key? 5? etc. (sharing PBIX &lt;A href="https://we.tl/t-ynvzHDkXIv" target="_blank"&gt;https://we.tl/t-ynvzHDkXIv&lt;/A&gt; and code at&amp;nbsp;&lt;A href="https://dax.do/yFMaeAbs5BRRWr/" target="_blank"&gt;https://dax.do/yFMaeAbs5BRRWr/&lt;/A&gt;&amp;nbsp;- data is slightly different, problem and result is the same)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the solution in SQL (copied the DB over using DAX Studio).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;This is what I get with DAX:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;You can see the intermediate table is actually fine, and the number of orders with 7 distinct product keys is 45 (see row num on tabled, ordered dec.). This is exactly the same as what SQL give us.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Question:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;How can I get the "no of sales orders" column correct, given I have the intermediate table correct?&lt;/LI&gt;&lt;LI&gt;Once I've got the the correct result in a table expression, how do I get one in a visual?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="css"&gt;DEFINE
MEASURE 'Sales'[Distinct Product Key Count] = DISTINCTCOUNT( 'Sales'[ProductKey] )

EVALUATE

VAR __tbl_count_product_keys_by_order_number = 
ADDCOLUMNS (
	DISTINCT ( 'Sales'[Order Number] ),
	"@Distinct Product Keys", [Distinct Product Key Count]
)

VAR __tbl_distinct_column_number_of_product_keys = 
	DISTINCT ( 
		SELECTCOLUMNS ( 
			__tbl_count_product_keys_by_order_number,
			"@No of Distinct Product Keys", [@Distinct Product Keys]
		)
	)
	
VAR result = 
ADDCOLUMNS(
	SUMMARIZE(
		__tbl_count_product_keys_by_order_number,
		[@Distinct Product Keys]
	),
	"no of sales orders", 
	CALCULATE( 
		COUNTROWS( __tbl_distinct_column_number_of_product_keys )
	)
)

// RETURN result ORDER BY [@Distinct Product Keys]

RETURN __tbl_count_product_keys_by_order_number ORDER BY [@Distinct Product Keys] DESC&lt;/LI-CODE&gt;</description>
    <pubDate>Sun, 13 Oct 2024 06:13:42 GMT</pubDate>
    <dc:creator>AhsenMajid</dc:creator>
    <dc:date>2024-10-13T06:13:42Z</dc:date>
    <item>
      <title>Distribution of one measure by another - pbix and dax.do code provided</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Distribution-of-one-measure-by-another-pbix-and-dax-do-code/m-p/4239886#M167801</link>
      <description>&lt;P&gt;I am using the Contoso db (dax.do).&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;There is a sales table, which is a fact table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are also customer, product, and order dimension tables.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I want to see the distribution of the count of distinct product keys by order number. Do most orders have just one product key? 5? etc. (sharing PBIX &lt;A href="https://we.tl/t-ynvzHDkXIv" target="_blank"&gt;https://we.tl/t-ynvzHDkXIv&lt;/A&gt; and code at&amp;nbsp;&lt;A href="https://dax.do/yFMaeAbs5BRRWr/" target="_blank"&gt;https://dax.do/yFMaeAbs5BRRWr/&lt;/A&gt;&amp;nbsp;- data is slightly different, problem and result is the same)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the solution in SQL (copied the DB over using DAX Studio).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;This is what I get with DAX:&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;You can see the intermediate table is actually fine, and the number of orders with 7 distinct product keys is 45 (see row num on tabled, ordered dec.). This is exactly the same as what SQL give us.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;Question:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;How can I get the "no of sales orders" column correct, given I have the intermediate table correct?&lt;/LI&gt;&lt;LI&gt;Once I've got the the correct result in a table expression, how do I get one in a visual?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="css"&gt;DEFINE
MEASURE 'Sales'[Distinct Product Key Count] = DISTINCTCOUNT( 'Sales'[ProductKey] )

EVALUATE

VAR __tbl_count_product_keys_by_order_number = 
ADDCOLUMNS (
	DISTINCT ( 'Sales'[Order Number] ),
	"@Distinct Product Keys", [Distinct Product Key Count]
)

VAR __tbl_distinct_column_number_of_product_keys = 
	DISTINCT ( 
		SELECTCOLUMNS ( 
			__tbl_count_product_keys_by_order_number,
			"@No of Distinct Product Keys", [@Distinct Product Keys]
		)
	)
	
VAR result = 
ADDCOLUMNS(
	SUMMARIZE(
		__tbl_count_product_keys_by_order_number,
		[@Distinct Product Keys]
	),
	"no of sales orders", 
	CALCULATE( 
		COUNTROWS( __tbl_distinct_column_number_of_product_keys )
	)
)

// RETURN result ORDER BY [@Distinct Product Keys]

RETURN __tbl_count_product_keys_by_order_number ORDER BY [@Distinct Product Keys] DESC&lt;/LI-CODE&gt;</description>
      <pubDate>Sun, 13 Oct 2024 06:13:42 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Distribution-of-one-measure-by-another-pbix-and-dax-do-code/m-p/4239886#M167801</guid>
      <dc:creator>AhsenMajid</dc:creator>
      <dc:date>2024-10-13T06:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Distribution of one measure by another - pbix and dax.do code provided</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Distribution-of-one-measure-by-another-pbix-and-dax-do-code/m-p/4240180#M167852</link>
      <description>&lt;P&gt;You're looking to calculate distribution of&amp;nbsp;_count_product_keys_by_order_number, that's to say,&amp;nbsp;_count_product_keys_by_order_number is a dimension; therefore it's no long a calculation on the fly, but a tangible (calculated) column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First create a calculated table in table view as what you did in&amp;nbsp;__tbl_count_product_keys_by_order_number; then put necessary column in a viz.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Oct 2024 18:01:31 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Distribution-of-one-measure-by-another-pbix-and-dax-do-code/m-p/4240180#M167852</guid>
      <dc:creator>ThxAlot</dc:creator>
      <dc:date>2024-10-13T18:01:31Z</dc:date>
    </item>
  </channel>
</rss>

