Desktop

Frequent Visitor
Posts: 5
Registered: ‎08-16-2018

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

Accepted Solutions
Highlighted
Posts: 171
Registered: ‎11-18-2016

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

[ Edited ]

Hi @tsailfc,

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

All Replies
Highlighted
Posts: 171
Registered: ‎11-18-2016

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

[ Edited ]

Hi @tsailfc,

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

Super User
Posts: 4,109
Registered: ‎01-14-2017

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

Hi,

Share a dataset and show the expected result.

Community Support Team
Posts: 1,591
Registered: ‎07-25-2018

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

Hi @tsailfc

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