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
naeljb
Helper I
Helper I

returned value with related tables

Hi,

 

I have the two following tables (household and member) linked by an ID.  In table household, how can I get the returned value (# people under 5) for each household?  What would be the DAX FUNCTION to get this value in ‘’# people under 5’’ column?  For example, for the first household with id =01, the returned number of people under 5 years old would be 2. For the second household with Id=02, the number of people under 5 would be 1

 

Household

Household ID

District

Sex of household head

# people  under 5 yrs old

01

A

Male

?

02

B

Female

?

 

Member

Household ID

Name

Sex

Age

01

A

Male

20

01

B

Female

2

01

C

Male

1

02

D

Female

3

02

E

Female

15

3 ACCEPTED SOLUTIONS
Phil_Seamark
Employee
Employee

Hi @naeljb

 

Assuming you have a relationship setup between Household and Members, please try the followingn Calcualated Column on Household

 

# People under 5 yrs old = CALCULATE(
COUNTROWS('Member'),
FILTER('Member','Member'[Age]<5),
RELATEDTABLE('Member')
)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

or a slightly shorter version of Calculated column :

=CALCULATE( COUNTROWS('Member'), 'Member'[Age] < 5 )

Or you can do a measure which in this case is same code (measure would be my preference):

 

Kids under 5:=CALCULATE( COUNTROWS('Member'), 'Member'[Age] < 5 )

 

@Phil_Seamark  one thing i don't understand in your version is the 'RELATEDTABLE('Member')' part - what is the thought behind including?

 

View solution in original post

Not sure I follow.  If you enter in @Phil_Seamark code as a calculated column as shown in 'Household' it will return for the respective household how many members are under 5....what is the output supposed to look like?

View solution in original post

8 REPLIES 8
naeljb
Helper I
Helper I

Thank you very much Phils.   It does tell me the total number of people under 5.  But, it doesn't return in table househod and  for each household the number of people under 5.  (i.e, I would like to get in the number of people under 5 for each of househod in table household). 

Not sure I follow.  If you enter in @Phil_Seamark code as a calculated column as shown in 'Household' it will return for the respective household how many members are under 5....what is the output supposed to look like?

Indeed   !!!  was  my mistake .  Thanks all for your help!!!

Phil_Seamark
Employee
Employee

Hi @naeljb

 

Assuming you have a relationship setup between Household and Members, please try the followingn Calcualated Column on Household

 

# People under 5 yrs old = CALCULATE(
COUNTROWS('Member'),
FILTER('Member','Member'[Age]<5),
RELATEDTABLE('Member')
)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thank sooo much Phil.  It works. 

or a slightly shorter version of Calculated column :

=CALCULATE( COUNTROWS('Member'), 'Member'[Age] < 5 )

Or you can do a measure which in this case is same code (measure would be my preference):

 

Kids under 5:=CALCULATE( COUNTROWS('Member'), 'Member'[Age] < 5 )

 

@Phil_Seamark  one thing i don't understand in your version is the 'RELATEDTABLE('Member')' part - what is the thought behind including?

 

Hi @mattbrice, more habit than anything and you are right it's not needed in this particular case,  There is some useful info in the Definity Guide to DAX about using RELATEDTABLE on the one side of a one to many relationships.

 

 


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

ok - well my only comment on that is to not use it useless it is needed.  I understand what it does, but i just wasn't clear on why it was included.  Thanks for responding.

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.