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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
huguest
Advocate II
Advocate II

LAX count values where column b = column a

Hello,

I have a Table that contains information about Parent and Child records together (ID, Parent_ID, Type, Gender).  I need to add 2 columns that calculate the number of children of each gender for each parent (Boy, Girl) but cannot figure out how to do it.

 

IDParent_IDTypeGenderBoyGirl
11Parent 31
22Parent 22
31ChildBoy  
41ChildBoy  
51ChildBoy  
61ChildGirl  
72ChildBoy  
82ChildBoy  
92ChildGirl  
102ChildGirl  

 

Thank you,

Hugues.

1 ACCEPTED SOLUTION

Got it @huguest

 

Here you go

 

Boy = 
IF (
    Table1[Type] = "Parent", 
    CALCULATE (
        COUNT ( Table1[Gender] ),
        Table1[Gender] = "Boy",
        ALLEXCEPT ( Table1, Table1[Parent_ID] )
    )
)

Girl = 
IF (
    Table1[Type] = "Parent", 
    CALCULATE (
        COUNT ( Table1[Gender] ),
        Table1[Gender] = "Girl",
        ALLEXCEPT ( Table1, Table1[Parent_ID] )
    )
)
)image.png

View solution in original post

5 REPLIES 5
nickchobotar
Skilled Sharer
Skilled Sharer

@huguest

 

Do you expect to get the results in the same table in a calculated column, or it's ok to use a measure and see your results like shown below?

Parent_IDBoyGirl
131
222

 

N-

Ideally as a calculated column in the same table.

Got it @huguest

 

Here you go

 

Boy = 
IF (
    Table1[Type] = "Parent", 
    CALCULATE (
        COUNT ( Table1[Gender] ),
        Table1[Gender] = "Boy",
        ALLEXCEPT ( Table1, Table1[Parent_ID] )
    )
)

Girl = 
IF (
    Table1[Type] = "Parent", 
    CALCULATE (
        COUNT ( Table1[Gender] ),
        Table1[Gender] = "Girl",
        ALLEXCEPT ( Table1, Table1[Parent_ID] )
    )
)
)image.png

Thank you, I will give it a try as soon as I get a chance.

Vvelarde
Community Champion
Community Champion

@huguest

 

Hi, try with this calculated column

 

Boy =
IF (
    Table3[Type] = "Parent",
    COUNTROWS (
        FILTER (
            Table3,
            Table3[Parent_ID] = EARLIER ( Table3[Parent_ID] )
                && Table3[Gender] = "Boy"
        )
    )
)

Regards

 

Victor

Lima - Peru




Lima - Peru

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.