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

Check if values in a table created by SELECTCOLUMNS exists in another table created by SELECTCOLUMNS

Hello,

I've created a measure that uses two SELECTCOLUMNS() functions to create two virtual tables with one column a piece. 

CHECK = VAR Table1 = SELECTCOLUMNS(FILTER('Base Table', 'Base Table'[Condition] = "1"), "1 Column", 'Base Table'[Transaction])

VAR Table2 = SELECTCOLUMNS(FILTER('Base Table', 'Base Table'[Condition] = "2"), "2 Column", 'Base Table'[Transaction])

RETURN
IF(Table1 IN Table2, "A exists in B", "A is not in B") 

This isn't working as expect and I think it's because of the IN operator, or it could be because I am using Direct Query and Table2 brings in over 1M rows exceeding the limit. Can anyone help here? 

2 ACCEPTED SOLUTIONS

Hi @tamerj1 ,

I'll try and create a mock-up of what my data looks like without sharing sensitive data. Thank you again for helping with this.

Both the Transaction and Material column can have duplicates and are not unique. Each Transaction and Material combination can also have a condition of 1, 2, or both. 

View solution in original post

@RYU209 

Please try

=
VAR CurrentCondition =
SELECTEDVALUE ( 'Base Table'[Condition] )
VAR T =
CALCULATETABLE (
VALUES ( 'Base Table'[Condition] ),
ALLEXCEPT ( 'Base Table', 'Base Table'[Transaction], 'Base Table'[Material] )
)
RETURN
IF ( COUNTROWS ( T ) = 2 && CurrentCondition = "2", 1 )

View solution in original post

12 REPLIES 12
tamerj1
Super User
Super User

Hi @RYU209 

please try

RETURN
IF ( ISEMPTY ( EXCEPT ( Table1, Table2 ) ), "A exists in B", "A is not in B") 

this will check if all values of A exist in B

If you want to check if at least one value of A exists in B then use

RETURN
IF ( NOT ISEMPTY ( INTERSECT ( Table1, Table2 ) ), "A exists in B", "A is not in B") 

in case it is only one value then both expressions will produce the same result

 

Hi @tamerj1 ,

My main goal is to go row by row in Table1 and check if that row exists in Table2. Then I plan on using this measure as a visual filter to restrict a Table visual to only show Transactions that exist in both Table1 and Table2. So it's not an all or nothing check but a row by row check. Would I need to restructure my approach here? 

@RYU209 

The values in you table visual are aggregated at which level?

@tamerj1 I'm not sure what that means. 

@RYU209 

I mean there is nothing wrong with this approach but I can see a contradiction between the approach and your description of the table visual. You have stated that you need to limit the transactions displayed by the visual which means the table visual displays the data at row level (no aggregation). In other words 1 row in the table visual = 1 row in the source data. While the approach suggests multiple rows in the filter context that are being filtered based on different conditions. I could go further and start proposing solutions based on my above understanding of the problem but perhaps I'm mistaken. Therefore, please provide more information like sample data and/or a screenshot of tge visual for better understanding of the problem. 

@tamerj


Correct, the table visual will behave as described. Please feel free to correct my approach as I am not super familiar with SELECTCOLUMNS(). 

@RYU209 
Please try

=
VAR T =
    CALCULATETABLE (
        VALUES ( 'Base Table'[Transaction] ),
        'Base Table'[Condition] = "2",
        ALLSELECTED ( 'Base Table' )
    )
RETURN
    COUNTROWS (
        FILTER (
            'Base Table',
            'Base Table'[Condition] = "1"
                && 'Base Table'[Transaction] IN T
        )
    )

@tamerj1 

Thank you for the detailed response! I didn't mention in the original question that the measure filter also needs to restrict Transactions based off a [Material] column. The Base Table can have duplicate Transactions each with a different Material and each row in the data set can also have a [Condition] of 1 or 2. I need to find a way to retrieve Transactions that have the same Transaction ID, Material, and have a condition of both 1 and 2. The table (visual) then needs to be restricted to only show Transactions that fall under this condition but ONLY show the transactions with [Condition] = 2. 

Sorry if this isn't clear! 

@RYU209 
Alright. It dose not seem to be complex. The only complex thing for me is that I have no idea how your data looks like. PLease share a sample or a screenshot for bettwer understanding of the problem.

Is the transaction ID a primary (unique) key in the table? If not then is material ID  a primary (unique) key in the table?

Please advise.

This is what the data looks like. There are other data elements but they are not relevant to how the Table (Visual) needs to be filtered.

The Table in Red denotes how the Visual should look like after filtering. The data on the left is how the raw data looks like.

RYU209_0-1674154525160.png

 

@RYU209 

Please try

=
VAR CurrentCondition =
SELECTEDVALUE ( 'Base Table'[Condition] )
VAR T =
CALCULATETABLE (
VALUES ( 'Base Table'[Condition] ),
ALLEXCEPT ( 'Base Table', 'Base Table'[Transaction], 'Base Table'[Material] )
)
RETURN
IF ( COUNTROWS ( T ) = 2 && CurrentCondition = "2", 1 )

Hi @tamerj1 ,

I'll try and create a mock-up of what my data looks like without sharing sensitive data. Thank you again for helping with this.

Both the Transaction and Material column can have duplicates and are not unique. Each Transaction and Material combination can also have a condition of 1, 2, or both. 

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.