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 do I prevent summing on a column in a Table where the rows are aggregations?

Hi all,

 

 

Let's say you have a Sale query and a StockCard query.  They are linked by StockID.  In the Stock table is a StockOnHand column.

 

How do you create a table visualisation that sums Sale values (saleValue, GST etc) and also shows values from the Stock query that are NOT aggregated.

 

eg.

2 sales for $10 each for the same Stock record.  Stock has StockOnHand of 100.

 

My issue is that the table shows...

 

Product    Total    StockOnHand

Coke         $20       200

 

Basically it is adding the stockOnHand twice because there are 2 sales.

 

This is killing me.

Free beer in Sydney for the winner.

 

Nick

 

6 REPLIES 6
himanshu56
Resolver II
Resolver II

Hi Nick,

 

Please try the below DAX query.

 

stockOnHand_Distinct =
SUMX (
    DISTINCT ( TableName[ProductName] ),
    CALCULATE ( DISTINCT ( TableName[stockOnHand] ) )
)

 

Thanks,

Himanshu

Anonymous
Not applicable

Hi,

 

Thanks for helping me.  Should that DAX be a measure on the Sales table or the Stock table?  It's giving me an error.

 

Nick

Anonymous
Not applicable

 

Error Message:
MdxScript(Model) (11, 91) Calculation error in measure 'Sales'[stockOnHand_Distinct]: A table of multiple values was supplied where a single value was expected.

 

Anonymous
Not applicable

Seems to work at the lowest level of my heirachy.  But when I Drill-Up, it throws that error.

 

Anonymous
Not applicable

I should add that the table has a 3 level heirachy.  Product, Sub Department and Department.

 

Not sure how to handle heirarchy in this particular situation.

May be you need to use Filter function. 

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.