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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
fanx
Frequent Visitor

Calculate a metric in detail table with rows filtered out

I am using a Header - Detail structure.

 

Table 1: Header

HeaderIDSales
1100
2150
3160

 

Table 2: Detail

HeaderIDProductQtyPrice
1A230
1B140
2C1150
3A230
3D250

 

I applied a slicer to filter product . It is easy for me to calculate metric in Table 1 with header including say Product A (HeaderID 1 and 3 are filtered).

 

However, I want to calculate the qty/sales of all items sold in the header which contains the product I selected in the slicer. I don't know how to do it.

Basically I want to see the below final extract if product A is selected in the slicer. Could anyone help?

 Qty
A4
B1
D2

 

 

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@fanx you can try following steps:

 

- create table using dax for products to use in slicer

 

Product = VALUES( Detail[Product] )

- use Product from Product Table on slicer, and following measure to calculate qty

 

Total Qty = 
VAR __selectedHeaderId = CALCULATETABLE( VALUES( Detail[HeaderID] ), Detail[Product] IN VALUES( Products[Product] ) )
RETURN
CALCULATE( SUM( Detail[Qty] ), __selectedHeaderId )

- add table visual, put product and Total Qty mesure from detail table and you will have the result



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

8 REPLIES 8
Ashish_Mathur
Super User
Super User

Hi,

If Product A is selected in the slicer, then why should A,B and D appear in the final output.


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

@Ashish_Mathur it is explain in main post by @fanx. Did you read that?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Yes, i did.  He selects 1 and 3 from Table1 and then Product A from Table2.  That should still only show Product A.


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

@Ashish_Mathur Ask is whatever product he selects, he want to show all the items of the headerid in which selected product exists. Anyhow I did already sent him the solution, feel free to go ahead if you have another option to solve it. 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

fanx
Frequent Visitor

Thank you both. It worked after removing the relationship. 

 

The business question I want to answer here is, for the order including item X (the ones I selected), which other items and what qty are sold together with it. That's why I want to calculate all the items in the order I filtered.

 

There is one more question on this, in my original model, I have a 'product' dimension table. It seems with this solution, I can only use product column from Detail table and not from product dimension table. when using product key from demension, it shows only the product A row (qty 4), no row for product B and D. but the total qty in the visual is correct (qty 7). Is there a way to walk around it?

parry2k
Super User
Super User

@fanx you can try following steps:

 

- create table using dax for products to use in slicer

 

Product = VALUES( Detail[Product] )

- use Product from Product Table on slicer, and following measure to calculate qty

 

Total Qty = 
VAR __selectedHeaderId = CALCULATETABLE( VALUES( Detail[HeaderID] ), Detail[Product] IN VALUES( Products[Product] ) )
RETURN
CALCULATE( SUM( Detail[Qty] ), __selectedHeaderId )

- add table visual, put product and Total Qty mesure from detail table and you will have the result



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

fanx
Frequent Visitor

Hi,

 

Thanks. I just tried. but it doesn't seem working. It still only shows the product A qty. Could you have another look at the sample file in the below link?

Power BI sample file

PS: Ideally, I would like to select the 'product' from 'product' table. because in my real model, I have more columns in my product table, e.g., category. and this could help me aggregate total qty to category level. But it there is no easy solution, I can go with the product level one.

 

Thanks again

@fanx you have relationship between product and detail table which is not required, remove that relationship and it will work.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors