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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
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.