Forum Discussion

hnguyen76's avatar
hnguyen76
Resolver II
6 years ago
Solved

DAX LeftouterJoin No Relationship

Hi All.

I'm attempting to create an attribute table from two fact tables in DAX. I'm fully aware that this is far easier and better to do in PowerQuery except that I'm using a database that has slow performance factor and the query takes forever to evaluate (even though I'm only pulling in a small amount of data). As an alternative I'd like to built this attribute table within DAX.


I want to pull just the distinct attributes from both fact tables so I can explode that within a table visual. These two facts are:

FACT_1

Ticket_IDCountryAmountSoldToSalesTypeYearMonthDateID.Key
1US100Party1Sales Order2020011-Jan-201^202001
2US102Party1Sales Order2020011-Jan-202^202001
3CAD104Party2Sales Order2020011-Jan-203^202001
4CAD500Party3Sales Order2020011-Jan-204^202001
5US5410Party1Sales Order2020011-Jan-205^202001
6CAD20Party4Sales Order2020011-Jan-206^202001
7CAD80Party3Sales Order2020011-Jan-207^202001
2US20Party1Sales Order2020011-Jan-202^202001
5US5400Party1Credit2020011-Jan-205^202001
5US400Party1Sales Order2020011-Jan-205^202001

 

FACT_2

Ticket_IDAmountApprovedCustomerYearMonthDateID.Key
11001Customer 1 Name2020011-Jan-201^202001
21020Customer 1 Name2020011-Jan-202^202001
31041Customer 2 Name2020011-Jan-203^202001
45000Customer 3 Name2020011-Jan-204^202001
554001Customer 1 Name2020011-Jan-205^202001
5101Customer 1 Name2020011-Jan-205^202001

 

Pretty common scenario.  If this is done in PowerQuery, I'd LEFTOUTERJOIN the FACT_1 ID.KEY to FACT_2 ID.KEY and return the distinct table values. This image result below is what I want:

As such, when I add this with my bridge table I'm retrieving the values I want:

So my attempt at DAX does not yield the expected result:

 

Any ideas on how to proceed?

  • hnguyen76's avatar
    hnguyen76
    6 years ago

    v-juanli-msft ,
    Thanks for the reply. Unfortunately I was looking for a route that did not consider using any relationships (active or inactive) while actively avoiding M-2-M. Considering performance vs data model size I opted with my original solution to use PowerQuery 

5 Replies

  • You can use a cross join in Dax but it will make things slow. You can use it inside the filter to have your condition.

    Also, use selectcolumns to rename and select columns as this will not Allow same name column.

     

    Use summarize of top of it.

    • hnguyen76's avatar
      hnguyen76
      Resolver II

      amitchandak ,

      CROSSJOIN is definitely out of the question. I tried it with my dataset yesterday and it returned me 2 billion rows and took about 20 minutes to evaluate. 

      • amitchandak's avatar
        amitchandak
        Super User

        I think the option you planning to use of power query is better. What you actally want to achieve using merge

  • v-juanli-msft's avatar
    v-juanli-msft
    Community Support

    Hi hnguyen76 

    two ways to get expected result as you provided:

    1. create relationships

    2. create inactive relationships(inactive relationships won't filter tables)

    Create calcualted columns

    amount2 = CALCULATE(SUM(Table2[Amount]),USERELATIONSHIP(Table1[ID.Key],Table2[ID.Key]))
    
    customer = LOOKUPVALUE(Table2[Customer],Table2[ID.Key],Table1[ID.Key])

    Best Regards
    Maggie
    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
    • hnguyen76's avatar
      hnguyen76
      Resolver II

      v-juanli-msft ,
      Thanks for the reply. Unfortunately I was looking for a route that did not consider using any relationships (active or inactive) while actively avoiding M-2-M. Considering performance vs data model size I opted with my original solution to use PowerQuery