cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Gijs93
New Member

Count the number of related records

Hi, 

 

I am struggling with a calculation in DAX. I want to add the column "Children" to my dataset (I have one fact_Table, as displayed below). For example, ID 2 shows up twice under Parent and therefore has 2 children. So the number of times the ID value pops up in other rows is the amount of Children records. 

 

I used COUNTROWS and LOOKUPVALUE to no avail, I am hoping anyone here knows how to calculate this column. 

 

Fact_Table

ID

Type

Parent

Status

Children

1

A

2

D

1

2

B

6

I

2

3

C

2

I

1

4

D

1

D

1

5

C

3

T

0

 

Thank you in advance, 
Best,

Gijs 

1 ACCEPTED SOLUTION
daxer
Solution Sage
Solution Sage

[Children] = // calculated column
var CurrentID = FT[ID]
var Result =
    COUNTROWS(
        FILTER(
            FT,
            FT[Parent] = CurrentID
        )
    )
RETURN 
    Result

View solution in original post

1 REPLY 1
daxer
Solution Sage
Solution Sage

[Children] = // calculated column
var CurrentID = FT[ID]
var Result =
    COUNTROWS(
        FILTER(
            FT,
            FT[Parent] = CurrentID
        )
    )
RETURN 
    Result

View solution in original post

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors