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
PradeepDive
Helper II
Helper II

Need Help - Filter tables using OR criteria from two table

Hi,

I have three tables and want to filter one out of 3 based on column values in other two tables 

 

Here is the explaination 

 

Table 1 -- 

Project ID, Resource ID, Hrs

 

Table 2 --

Project ID's

 

Table 3

Resource ID

 

I want to filter Table 1  using below criteria

 Table 1 [Project ID] = Table 2 [Project ID]  OR  Table 1 [Resource ID] = Table 3 [Resource ID]

 

The OR part in this criteria is important.  Please help.

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @PradeepDive ,

 

You can use LOOKVALUE function. However, if there is a relationship between tables, it's more efficient to use the RELATED function.

 

Sample data.

Table 1

vstephenmsft_3-1638516297763.png

 

Table 2

vstephenmsft_5-1638516303593.png

 

Table 3

vstephenmsft_6-1638516312026.png

 

 

1.If there're no relationships.

You can create a calculated table as follows.

Table =
SUMMARIZE (
    FILTER (
        ADDCOLUMNS (
            'Table 1',
            "c1",
                LOOKUPVALUE (
                    'Table 2'[Project ID],
                    'Table 2'[Project ID], 'Table 1'[Project ID]
                ),
            "c2",
                LOOKUPVALUE (
                    'Table 3'[Resource ID],
                    'Table 3'[Resource ID], 'Table 1'[Resource ID]
                )
        ),
        [c1] = [Project ID]
            && [c2] = [Resource ID]
    ),
    [Hrs],
    [Project ID],
    [Resource ID]
)

vstephenmsft_2-1638516221055.png

 

 

If there're relationships.

vstephenmsft_0-1638516109882.png

You can create a calculated table as follows..

Table 4 =
SUMMARIZE (
    FILTER (
        ADDCOLUMNS (
            'Table 1',
            "c1", RELATED ( 'Table 2'[Project ID] ),
            "c2", RELATED ( 'Table 3'[Resource ID] )
        ),
        [c1] = [Project ID]
            && [c2] = [Resource ID]
    ),
    [Hrs],
    [Project ID],
    [Resource ID]
)

vstephenmsft_1-1638516202820.png

 

 

Best Regards,

Stephen Tao

 

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

7 REPLIES 7
v-stephen-msft
Community Support
Community Support

Hi @PradeepDive ,

 

You can use LOOKVALUE function. However, if there is a relationship between tables, it's more efficient to use the RELATED function.

 

Sample data.

Table 1

vstephenmsft_3-1638516297763.png

 

Table 2

vstephenmsft_5-1638516303593.png

 

Table 3

vstephenmsft_6-1638516312026.png

 

 

1.If there're no relationships.

You can create a calculated table as follows.

Table =
SUMMARIZE (
    FILTER (
        ADDCOLUMNS (
            'Table 1',
            "c1",
                LOOKUPVALUE (
                    'Table 2'[Project ID],
                    'Table 2'[Project ID], 'Table 1'[Project ID]
                ),
            "c2",
                LOOKUPVALUE (
                    'Table 3'[Resource ID],
                    'Table 3'[Resource ID], 'Table 1'[Resource ID]
                )
        ),
        [c1] = [Project ID]
            && [c2] = [Resource ID]
    ),
    [Hrs],
    [Project ID],
    [Resource ID]
)

vstephenmsft_2-1638516221055.png

 

 

If there're relationships.

vstephenmsft_0-1638516109882.png

You can create a calculated table as follows..

Table 4 =
SUMMARIZE (
    FILTER (
        ADDCOLUMNS (
            'Table 1',
            "c1", RELATED ( 'Table 2'[Project ID] ),
            "c2", RELATED ( 'Table 3'[Resource ID] )
        ),
        [c1] = [Project ID]
            && [c2] = [Resource ID]
    ),
    [Hrs],
    [Project ID],
    [Resource ID]
)

vstephenmsft_1-1638516202820.png

 

 

Best Regards,

Stephen Tao

 

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

Thank Stephen Tao for the detailed explaination. 

 

My mistake, I did not explain in my question.

There is no relationship between tables, I am trying to achieve the above result in Power query which I will later use to create a dataflow.

 

2nd is my Table 1 is huge with 1.5M rows of data.  I am not sure how efficiently the Dax summarize will work in terms of performance and speed.

 

Any suggestions

Hi @PradeepDive ,

 

Here's the solution in Power Query.

1.Merge queries from two tables.

vstephenmsft_0-1638777695107.png

vstephenmsft_1-1638777710557.png

You’ll get this.

vstephenmsft_2-1638777762151.png

2.Expand columns you need.

vstephenmsft_3-1638777780367.png

3.Add a custom column.

= if [Project ID]=[Table 2.Project ID] and [Resource ID]=[Table 3.Resource ID] then 1 else 0

vstephenmsft_4-1638777797197.png

4.Filter the rows which value is 1.

vstephenmsft_5-1638777857458.png

vstephenmsft_7-1638777879493.png

5.You can remove the unneeded columns.

vstephenmsft_6-1638777869248.png

 

Best Regards,

Stephen Tao

 

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

 

Thanks Stephen,

 

I am already using the same approach currently, but as my tables are huge it takes lots of time for merging. I was looking for something which can use to get the output in less and if possible in single line (but not necessary)

 

Appreciate your time to answer my query though. 

smpa01
Super User
Super User

@PradeepDive  it would probably give you the same

Measure = 
CALCULATE (
    SUM ( t1[Hrs] ),FILTER(VALUES(t1[Project ID]),t1[Project ID]=MAX(t2[Project ID])))
+
CALCULATE (
    SUM ( t1[Hrs] ),FILTER(VALUES(t1[Resource ID]),t1[Resource ID]=MAX(t3[Resource ID])))
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Appreciate quick reply @smpa01  but this is not what I am looking for, I want to filter the table 1 based on values in Table 2 or 3 

@PradeepDive  in that case can you provide some sample data and expected output.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

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.

Top Solution Authors
Top Kudoed Authors