Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
I am using the Contoso db (dax.do).
There is a sales table, which is a fact table.
There are also customer, product, and order dimension tables.
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 https://we.tl/t-ynvzHDkXIv and code at https://dax.do/yFMaeAbs5BRRWr/ - data is slightly different, problem and result is the same)
This is the solution in SQL (copied the DB over using DAX Studio).
This is what I get with DAX:
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.
Question:
Thanks!
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
Solved! Go to Solution.
You're looking to calculate distribution of _count_product_keys_by_order_number, that's to say, _count_product_keys_by_order_number is a dimension; therefore it's no long a calculation on the fly, but a tangible (calculated) column.
First create a calculated table in table view as what you did in __tbl_count_product_keys_by_order_number; then put necessary column in a viz.
Expertise = List.Accumulate( {Days as from Today}, {Skills and Knowledge}, (Current, Everyday) => Current & Day.LearnAndPractise(Everyday) ) |
You're looking to calculate distribution of _count_product_keys_by_order_number, that's to say, _count_product_keys_by_order_number is a dimension; therefore it's no long a calculation on the fly, but a tangible (calculated) column.
First create a calculated table in table view as what you did in __tbl_count_product_keys_by_order_number; then put necessary column in a viz.
Expertise = List.Accumulate( {Days as from Today}, {Skills and Knowledge}, (Current, Everyday) => Current & Day.LearnAndPractise(Everyday) ) |
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 21 | |
| 12 | |
| 9 | |
| 5 | |
| 5 |