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
1984
Frequent Visitor

DAX LOOKUP IF AND COUNT

Hi 

 

I've been away from DAX for some time and trying to create a column with a calculation.

 

I have two tables with a 1:many relationship.

I would like to create a column in Table 1 (1 side) that lookup in table 2 at how many rows for each ID have the status "Complete" in the status column contained in table 2?

 

Like I say new returner so probably a simple fix pls be kind 🙂

 

 

2 REPLIES 2
v-kaiyue-msft
Community Support
Community Support

Hi @1984 ,

I want to acknowledge valuable input provided by @lbendlin . Their initial ideas help guide my approach. However, I noticed that more details are needed to fully understand this issue.


I created two tables and created a one-to-many relationship for them.

vkaiyuemsft_0-1714117119799.png


Create a calculated column in the "table" table for counting.

StatusCount =
VAR_count=
CALCULATE(
COUNTROWS('Table 2'),
RELATEDTABLE('Table 2'),
'Table 2'[status] = "Complete"
)
RETURN
IF(_count = BLANK(),0,_count)

vkaiyuemsft_1-1714117146303.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

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

lbendlin
Super User
Super User

Read about RELATEDTABLE. That allows you to look into the "many"  side of a relationship.

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.