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
miguelsus2000
Helper III
Helper III

Calculating values outside selected items in DAX

Hi,

 

I have a 2 tables that interact with each other, Table A and Table B.

 

Table A shows a person with # of relatives (e.g. brother, sister, etc)

Person      #Total Relatives  

John              3

Mary             2

 

Table B Lists details of each Relative

Relative               Height     Age 

John_Brother      6              21

John_Dad            5.7           52

John_Sis              5.2           17

Mary_Sis             5.2           15

Mary_Mom          5.1          48

 

What i want to do is select John in table A and John_Dad in table B and still be able to see in Table A that John has 3 relatives.  Instead, it only shows 1 relatives because that's what's been selected even though it has 3.

I tried this, but ican't get any where:

 
Total Relatives = 
calculate (
COUNTROWS('TableB'),
filter(
All ('TableA'[Relatives]),'TableA'[Person] <> BLANK()
)
)
 
I appreciate your help.

 

 

1 ACCEPTED SOLUTION
miguelsus2000
Helper III
Helper III

Thank you Everyone... i decided to go with a new table (using the summarize command), which worked out very well.  Thank you for the various ideas.

View solution in original post

8 REPLIES 8
miguelsus2000
Helper III
Helper III

Thank you Everyone... i decided to go with a new table (using the summarize command), which worked out very well.  Thank you for the various ideas.

VahidDM
Super User
Super User

Hi @miguelsus2000 

 

You can create a measure as bellow for Relative and use that in your first table:

Relative =
CALCULATE(COUNTROWS('Table'),REMOVEFILTERS('Table'[Relative ]))
 
output:
VahidDM_0-1648422426394.png

 

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

 
Jihwan_Kim
Super User
Super User

Hi,

I am not sure if I understood your question correctly, but please check the below picture and the attahced pbix file.

 

Picture1.png

 

Total number of relatives: =
VAR currentperson =
    MAX ( TableA[Person] )
RETURN
    COUNTROWS ( FILTER ( TableB, LEFT ( TableB[Relative], 4 ) = currentperson ) )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Hi Jihwan... this is close, 2 observations:

  1. the data in Table A and in Table B really come from the same table (let me call Table C- I expanded below). and
  2. when you selected in the slicer, the smaller table shows two relatives for John and 1 for Mary.  I still want it to display 3 relatives for John and 2 for Mary no matter what the slicer selection is.  Hope this helps and thank you for your help.

 

 

Table C This is where all the data comes from . Table A and B are displayed separately on the dashboard for the user to select the data.

Person    Relative               Height     Age 

John       John_Brother      6              21

John       John_Dad            5.7           52

John       John_Sis              5.2           17

Mary       Mary_Sis             5.2           15

Mary       Mary_Mom          5.1          48

PaulDBrown
Community Champion
Community Champion

How do the tables interact?





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






All the data from Table A and Table B comes from the same source table, but i split them visually into A & B for data slicing & dicing on the dashboard.  So the source table looks like this, which looks mostly like Table B:

 

John    John_Brother  6     21

John    John_Dad       5.7   52

etc....

 

HOpe this answers your question.

 

If you set up the model as follows

model.jpgYou can set up the visual with the slicers and table with the fields from the Dimension tables and with this measure:

Number of relatives = 
CALCULATE(COUNT('Relative Table'[RelativeT]), ALL('Relative Table'[RelativeT]))

You will get

result.jpg

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Hi Paul... I'm going to try this later today and get back.


Thank you..

M

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.