Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How to group products by brand in each order to find an average brand per order

I have the transaction table that contains columns order_id, brand, SKU and quantity (see table below). I want to know the average brand per order id. For example, the table below show 3 order id (0001, 0002 and 0003), order id 0001 contains 3 brands (A, B and C), order id 0002 contains 2 brands and order id 0003 contains 1 brand. So, the average brand per order id should be (3+2+1)/3 = 2 brands per order id.

How can I write DAX to get this information? I have been stuck for several days 😞

 

gameez_0-1667877549418.png

 

Thanks in advance!

1 ACCEPTED SOLUTION

Reivse the measure to

No of Brands = DISTINCTCOUNT(Sheet1[brand])

The answer will be 2.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

11 REPLIES 11
Ashish_Mathur
Super User
Super User

Hi,

Write these measures

Number of order ID = distinctcount(Data[Order_id])

Qty = sum(Data[Quantity])

Total = SUMX(VALUES(Data[Order_ID]),[Qty])

Avg = divide([Total],[Number of order ID])

Drag the Avg measure to a card visual.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Thank you Ashish. I think your solution give me an average quantity per order id, but what I'm looking for is average brand per order id.

You are welcome.  Try these

Number of order ID = distinctcount(Data[Order_id])

Number of brands = counta(Data[Brand])

Total = SUMX(VALUES(Data[Order_ID]),[Number of brands])

Avg = divide([Total],[Number of order ID])

Drag the Avg measure to a card visual.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

I recieved a calculation error in measure "Number of brands" due to the function SUM cannot work with values of type String. 😞

  

Replace SUM() with COUNTA().


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Unfortunately, it's not working. I try use the dummy table that I attached with this trend. Using your solution gave me 2.33 brands per order, but the right answer must be 2 brands per order.

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Here is the link.

Brand per Order 

Regards,

Krittapas T.

Reivse the measure to

No of Brands = DISTINCTCOUNT(Sheet1[brand])

The answer will be 2.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Access denied message.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Sorry for that. I just changed access setting at the moment. You can open the link now. Thank you.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.