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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
data_model
Frequent Visitor

Left outer join on many-many relationship in Direct query Model

Hello,

 

I am trying to build a report on Direct query (for real-time need) based semantic model with 2 tables, and the relationship between them is many-many due to the nature of the data. We need to create a visual mimicing the below sql. i.e., display items that exists in A but missing in B (kind of look up). 

select A.*

from tbl A left outer join tbl B

    on A.ID = B.ID

where B.Name is null and A.create_dt > '2001-01-01'

I tried to create a DAX based table but it is becoming import mode and we want this to be real-time and data volume is high.

Probably due to direct query mode and many-many, unable to create a lookup column in A using RELATED DAX function. This seems simple but cannot get it to work ( i may be missing something). Appreciate any help. 

Thanks

2 ACCEPTED SOLUTIONS
v-yiruan-msft
Community Support
Community Support

Hi @data_model ,

I created a sample pbix file(see the attachment), please check if that is what you want. You can follow the steps below to get it:

1. Create a measure as below

Flag = 
VAR _id=SELECTEDVALUE('A'[ID])
VAR _date=SELECTEDVALUE('A'[create_dt])
RETURN IF(NOT(_id IN VALUES('B'[ID]))&&_date>DATE(2001,1,1),1,0)

2. Create a table visual which the Fields options all from the table A

3. Apply a visual-level filter on the above table visual with the condition (Flag is 1)

vyiruanmsft_0-1721788897449.png

Best Regards

Community Support Team _ Rena
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

Hi @data_model ,

You can create a measure as below and replace [Count of ID2] with the new measure on the matrix.

Measure =
VAR _tab =
    FILTER (
        'Delta (Base)',
        NOT ( 'Delta (Base)'[ID] IN VALUES ( 'B'[ID] ) )
            && 'Delta (Base)'[create_dt] > DATE ( 2022, 1, 1 )
            && 'Delta (Base)'[create_dt] <> BLANK ()
    )
RETURN
    COUNTAX ( _tab, [ID] )

vyiruanmsft_0-1721986591449.png

Best Regards

Community Support Team _ Rena
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
data_model
Frequent Visitor

@v-yiruan-msft  Thanks for taking time and the solution. For some reason, i couldn't be able to download your file (probably blocked in our network). But am able to borrow your code, it worked and got the result i am looking for. 

Couple of observations/questions,

Overall response time is 3-4times longer vs using my entire sql via native/direct query ( 7000ms vs 24000ms). When i looked at the generated query (via performance analyzer), PBI produced multiple queries (one for tbl1 with all the visual columns, another for tbl1 just with the id column , another for tbl2 with it's id column) and seems join/processing happening in the PBI layer. If so, it may be a problem as these tables are large.

 

Table visual giving the data i need, but matrix visual returns no data (i assume this may be selectedvalue function as matrix visual is just some description column and count of id).

 

Thanks again

 

 

Hi @data_model ,

How did you set your matrix visual?  Could you please provide the related Fields settings and screenshot? Thank you.

Best Regards

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

Here is the matrix visual setup. Both the columns in this visual are from the tbl1. Hope this helps. Thanks

data_model_0-1721929802852.png

 

Hi @data_model ,

You can create a measure as below and replace [Count of ID2] with the new measure on the matrix.

Measure =
VAR _tab =
    FILTER (
        'Delta (Base)',
        NOT ( 'Delta (Base)'[ID] IN VALUES ( 'B'[ID] ) )
            && 'Delta (Base)'[create_dt] > DATE ( 2022, 1, 1 )
            && 'Delta (Base)'[create_dt] <> BLANK ()
    )
RETURN
    COUNTAX ( _tab, [ID] )

vyiruanmsft_0-1721986591449.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
v-yiruan-msft
Community Support
Community Support

Hi @data_model ,

I created a sample pbix file(see the attachment), please check if that is what you want. You can follow the steps below to get it:

1. Create a measure as below

Flag = 
VAR _id=SELECTEDVALUE('A'[ID])
VAR _date=SELECTEDVALUE('A'[create_dt])
RETURN IF(NOT(_id IN VALUES('B'[ID]))&&_date>DATE(2001,1,1),1,0)

2. Create a table visual which the Fields options all from the table A

3. Apply a visual-level filter on the above table visual with the condition (Flag is 1)

vyiruanmsft_0-1721788897449.png

Best Regards

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

March2025 Carousel

Fabric Community Update - March 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors