DAX Formula (NOT IN)

ernolan

New Member
Joined
Jul 12, 2018
Messages
1
This should be very simple. It certainly is in standard SQL. I have yet to find a way to do this with DAX. Simply put, I’m looking for a way to grab all of the records that don’t have a corresponding value in another table. For the SQL Gurus, this is simply done with a NOT IN clause.

Perhaps the illustration will help. The ATable has the one-to-many relationship with the BTable. For every primary key in the ATable, there maybe no values or a list of values in the BTable.

Let’s say the I want all of the records in the ATable that don’t have an Action Code value of “2” in the BTable. Based on the illustration below, I would get records 1001 and 1003. Records 1002 and 1004 have a value of “2” so I’m not interested in them.

Please and thanks in advance for any ideas you have. Cheers.


ATable BTable
RFSID RFSID Action Code
1001 1001 1
1002 1001 3
1003 1002 1
1004 1002 2
1002 3
1003 1
1003 3
1004 1
1004 2
1004 3
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Can think of a few ways to do this, I can't quite follow your data structure to write the exact code:

1 Use the EXCEPT formula. If you first filter table A so that it includes the items that DO match, and then use that as the second table expression in the EXCEPT. Pseudo code is something like:

Code:
EXCEPT (
    TableA,
    CALCULATETABLE (
        TableA,
        FILTER (
            TableB,
            TableB[Col] = 2
        )
    )
)

2 Use the CONTAINS formula with a NOT. Again Pseudocode

Code:
FILTER (
    TableA,
    NOT ( CONTAINS ( 
        TableB,
        TableB[Col],
        2)
    )
)
)


Hope this is more helpful than nothing.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,191
Members
453,021
Latest member
pingpong7117

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top