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
smpa01
Super User
Super User

Optimizing Left Anti in DAX Query

Hi,

My source data is following.

Table Name _dim

 

_dimID_dimName_dimAddr
A1Name1Addr1
A2Name2Addr2
A3Name3Addr3
A4Name4Addr4
A5Name5Addr5
A6Name6Addr6
A7Name7Addr7
A8Name8Addr8
A9Name9Addr9
A10Name10Addr10

 

Table Name _factAddr

 

_factAddress
Addr2
Addr4
Addr6

 

Table Name _factNm

_factName
Name1
Name1
Name4
Name4
Name4
Name8
Name8

 

There is no relationship between this 3 tables. I want to end up with a _dim table that does not have _factAddress from _factAddr and _factName from _factNm like following

 

_dimID_dimName_dimAddr
A3Name3Addr3
A5Name5Addr5
A7Name7Addr7
A9Name9Addr9
A10Name10Addr10

 

In reality, I am performing this on a _dim with 8M+ rows , wirh _factNm and _factAddr with respectively 1M+ and 5M+ rows. I want to optimize my query and so far I came up with following

 

EVALUATE
--option1--
VAR _01 =
    FILTER (
        NATURALINNERJOIN (
            _dim,
            EXCEPT ( VALUES ( _dim[_dimName] ), VALUES ( _factNm[_factName] ) )
        ),
        NOT _dim[_dimAddr] IN VALUES ( _factAddr[_factAddress] )
    )
--option2--    
VAR _02 =
    CALCULATETABLE (
        _dim,
        EXCEPT ( VALUES ( _dim[_dimName] ), VALUES ( _factNm[_factName] ) ),
        EXCEPT ( VALUES ( _dim[_dimAddr] ), VALUES ( _factAddr[_factAddress] ) )
    )
--option3--    
VAR _03 =
    FILTER (
        _dim,
        NOT _dim[_dimName]
            IN VALUES ( _factNm[_factName] )
                && NOT _dim[_dimAddr] IN VALUES ( _factAddr[_factAddress] )
    )
RETURN
    _01

 

 

In terms of total query duration, Option1 takes the least duration (option 1<2<3). Is there a better way of other than above to reach my goal?

 

Thank you in advance.

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
1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@smpa01 cannot test the performance but can you try this, change column name as per your model.

 

New Dim = 
VAR __table = 
UNION ( 
CALCULATETABLE ( Dim,  TREATAS ( VALUES ( FactAddress[Address] ), Dim[_dimAddr] ) ),
CALCULATETABLE ( Dim,  TREATAS ( VALUES ( FactName[Name] ), Dim[_dimName] ) )
)
RETURN EXCEPT ( Dim, __table )

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

1 REPLY 1
parry2k
Super User
Super User

@smpa01 cannot test the performance but can you try this, change column name as per your model.

 

New Dim = 
VAR __table = 
UNION ( 
CALCULATETABLE ( Dim,  TREATAS ( VALUES ( FactAddress[Address] ), Dim[_dimAddr] ) ),
CALCULATETABLE ( Dim,  TREATAS ( VALUES ( FactName[Name] ), Dim[_dimName] ) )
)
RETURN EXCEPT ( Dim, __table )

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

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.