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
83-guy
New Member

DAX - Is it possible to query one table and use the results to query another table?

Hello,

 

I am new to Power BI and am trying to learn my way around it. Is it possible to query one table and use the results from that query to query another table based on the key (in this case the ID)? For example, I have these two tables as a sample. Could I find everyone in Table1 that has a yes under "Has a pet" and then use the results to then grab all of their email addresses based on the ID in table2?

 

83guy_0-1713901503385.png

 

Would some other system work better for this?

 

1 ACCEPTED SOLUTION

Hi @83-guy ,

I’d like to acknowledge the valuable input provided by @Ashish_Mathur and @Bipin-Lala . Their initial ideas were instrumental in guiding my approach. However, I noticed that further details were needed to fully understand the issue.  

In my investigation, I took the following steps: 

I create two tables as you mentioned.

vyilongmsft_0-1714118006643.png

vyilongmsft_1-1714118071055.png

I think you can create a measure, it will help you get what you want.

Measure = 
VAR _ID =
    MAX ( 'Table 1'[ID] )
VAR _vtable =
    SELECTCOLUMNS (
        'Table 2',
        "_ID2", 'Table 2'[ID],
        "_Email", 'Table 2'[Email Address],
        "_Phone", 'Table 2'[Phone #]
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Table 1'[Has a pet] ) = "Yes",
        MAXX ( FILTER ( _vtable, [_ID2] = _ID ), [_Email] )
    )

vyilongmsft_2-1714118330215.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Assuming no entry in the ID column of Table2 repeats, write this calculated column formula in Table1

E-mail address = if('Table1'[Has a pet])="Yes",related('Table2'[Email address]),blank())

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Bipin-Lala
Responsive Resident
Responsive Resident

Hi @83-guy,

 

Yes, it's absolutely possible to query one table and use the results to query another table based on a key (such as an ID). You can achieve this by creating relationships between tables.

  • Create a relationship between Table 1 and Table 2 based on the ID column. The ID column will help you uniquely identify Name in Table 1 and corresponding Email & Phone in Table 2


BipinLala_1-1713903698805.png

  • Once you have created the relationship, you can drag fields from both the tables together
    BipinLala_2-1713903770904.png
  • You can apply a filter on the Has A Pet column to filter and display only people having pets

BipinLala_3-1713903863931.png

 

Hopefully, this solves your problem. If you are looking for some specific results or have different requirements, feel free to post here and I will try to help.

 

 

 

 

 

Is this possible in a DAX query? Essentially, I wish to have power automate run a query to grab the email addresses.

 

Hi @83-guy ,

I’d like to acknowledge the valuable input provided by @Ashish_Mathur and @Bipin-Lala . Their initial ideas were instrumental in guiding my approach. However, I noticed that further details were needed to fully understand the issue.  

In my investigation, I took the following steps: 

I create two tables as you mentioned.

vyilongmsft_0-1714118006643.png

vyilongmsft_1-1714118071055.png

I think you can create a measure, it will help you get what you want.

Measure = 
VAR _ID =
    MAX ( 'Table 1'[ID] )
VAR _vtable =
    SELECTCOLUMNS (
        'Table 2',
        "_ID2", 'Table 2'[ID],
        "_Email", 'Table 2'[Email Address],
        "_Phone", 'Table 2'[Phone #]
    )
RETURN
    IF (
        SELECTEDVALUE ( 'Table 1'[Has a pet] ) = "Yes",
        MAXX ( FILTER ( _vtable, [_ID2] = _ID ), [_Email] )
    )

vyilongmsft_2-1714118330215.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Bipin-Lala
Responsive Resident
Responsive Resident

Hi @83-guy,

 

As @Ashish_Mathur mentioned, you can use the RELATED function to pull the email addresses from Table 2 to Table 1 for people having a pet.

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.