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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
cretak
Frequent Visitor

[DAX Help] Counting rows from related table with conditions

Hi all,

 

I am still finding my way in the world of PowerBI 🙂 Here my issue:

 

I have two tables who are related with a 1:M

 

Table Orders:

Order IDName
1Neighbour
2Child
3Mom

 

Table LineItems:

LineItem IDOrder IDItem Type
11Pants
21Underwear
32Pants
43Underwear
53Underwear

 

My result should simply look like this:

Table Orders:

Order IDNameCount Underwear
1Neighbour1
2Child0
3Mom2

 

It means I just want to add the count of Underwear per order. All I got is the total count so far. I didnt get the relationship working in DAX.

 

Sorry for the inconvenience and many thanks for the help and support,

Oli

 

4 REPLIES 4
cretak
Frequent Visitor

I am currently travelling and cant test it! Will come back to you over the course of the week! Many thanks for the feedback already

Anonymous
Not applicable

Hi,

Thanks for the solutions @muhammad_786_1  and @audreygerred offered, and i want to offer some more infotmation for user to refer to.

hello @cretak . you can create a measure.

MEASURE =
VAR a =
    COUNTROWS ( FILTER ( LineItems, [Item Type] = "Underwear" ) )
RETURN
    a + 0

Output

vxinruzhumsft_0-1729474660715.png

Best Regards!

Yolo Zhu

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

muhammad_786_1
Super User
Super User

Hi,

 

You can also create a calculated column directly in the Orders table to achieve this by using this DAX:

 

muhammad_786_1_0-1729258770815.png

 

Best Regards,
Muhammad Yousaf

 

If this post helps, then please consider "Accept it as the solution" to help the other members find it more quickly.

 

LinkedIn

audreygerred
Super User
Super User

Hi! First, I made a measure for the total row count on the LineItems table:

Total Row Count = COUNTROWS(LineItems)
 
Next, I created the measure to look for only Underwear. I used the quick measure feature and chose filtered value. First, click the three dots next to the Total Row Count measure you just made. Then, select New quick measure. From the drop-down, select Filtered value, ensure that Total Row Count measure is in the Base Value well, then in the filter area put in Item Type and select Underwear from the drop-down - click Add.
audreygerred_0-1729258081970.png

 

 You now have your new measure with this for the DAX: 
Total Row Count for Underwear =
CALCULATE([Total Row Count], 'LineItems'[Item Type] IN { "Underwear" })
 
Now, you can make your visual:
audreygerred_1-1729258216995.png

 

 




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

Proud to be a Super User!





Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

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.