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

Average the sum of sales for each transaction where transaction contains item "X"

I am trying to write a DAX formula where I am able to take the average basket size for a basket containing item "A".

 

for each basket containing item "A", sum the sales in each basket and then take the average across all baskets. Baskets containing item "A" can contain other items. These items must be included in the sum of sales.

 

Currently, the DAX formula below is summing only the item I have selected in a slicer. I need this DAX to sum across all items in transactions containing the item selected in the slicer.

 

 

VAR b = SUMMARIZE ( Sales, Sales[TrxID], "basket_sales_sum", SUM ( Sales[Sales] ) )
RETURN
    AVERAGEX ( b, [basket_sales_sum] )

 

1 ACCEPTED SOLUTION
richbenmintz
Solution Sage
Solution Sage

Hi @Anonymous,

 

have a look at the following Measure

 

TRX with A =
VAR hasItemTable = CALCULATETABLE('Sales', Sales[Item] = "A")
return
CALCULATE(
divide(sum(Sales[Amount]),COUNTROWS(VALUES('Sales'[TrxId]))),
filter('Sales', CONTAINS(hasItemTable,[trxId], Sales[TrxId]) )
)
 

-> define table with only rows that contain "A" type of Item

-> calculate the basket / the number of trx where the trxId exists in the in the first step

 

Richard



I hope this helps,
Richard

Did I answer your question? Mark my post as a solution! Kudos Appreciated!

Proud to be a Super User!


View solution in original post

3 REPLIES 3
v-cherch-msft
Employee
Employee

Hi @Anonymous

 

Could you share some data which could reproduce your scenario and your desired output?

How to Get Your Question Answered Quickly

 

Regards,

Cherie

Community Support Team _ Cherie Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Ashish_Mathur
Super User
Super User

Hi,

 

Share a dataset and show the expected result.


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

Hi @Anonymous,

 

have a look at the following Measure

 

TRX with A =
VAR hasItemTable = CALCULATETABLE('Sales', Sales[Item] = "A")
return
CALCULATE(
divide(sum(Sales[Amount]),COUNTROWS(VALUES('Sales'[TrxId]))),
filter('Sales', CONTAINS(hasItemTable,[trxId], Sales[TrxId]) )
)
 

-> define table with only rows that contain "A" type of Item

-> calculate the basket / the number of trx where the trxId exists in the in the first step

 

Richard



I hope this helps,
Richard

Did I answer your question? Mark my post as a solution! Kudos Appreciated!

Proud to be a Super User!


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.