Forum Discussion

Hamzehn's avatar
Hamzehn
Frequent Visitor
5 years ago
Solved

How Can I Create a RANKX Measure Without Triggering a Crossjoin?

Hi, I have two tables Companies and Transactions that have a 1-to-many company-to-transaction relationship and are linked in the model by a Company ID field.

 

The Companies table has the following fields:

  1. Company ID
  2. Company Name

While the Transactions table has the following fields (note the fund field in particular - a single company can have multiple transactions with 1 or more fund(s)):

  1. Transaction ID
  2. Related Company ID
  3. Date
  4. Fund
  5. Amount

I'm trying to create a measure (DateRank) that ranks the transactions by date in each Company-Fund group and then display that in a table that shows the Company Name, Fund, Transaction ID, and calculated rank.

 

I haven't been able to do this without ending up with a Cartesian product of the two tables where the rank is calculated correctly for rows where the Companies[Company ID] matches the Transactions[Related Company ID], but the table also ends up having extra rows for all items in the Transactions table (even the ones where the company id's don't match) with the calculated value being 1.

 

As part of my research online I found a bunch of blogs (example) that talk about DAX auto-exist resulting in behavior like this, but while they did a really good job of explaining why that behavior was happening I couldn't find in them any solution that worked for my use case.

 

I would really appreciate someone's help here as there must be some way to do this!

 

Here is the formula that I have so far:

 

 

 

Measure DateRank =
    VAR thisFund = SELECTEDVALUE(Transactions[Fund])
    VAR thisDate = SELECTEDVALUE(Transactions[Date])
    Return
        CALCULATE(
            RANKX(
                ALLSELECTED(Transactions),
                Transactions[Date],
                thisCloseDate,
                DESC
            ),
            KEEPFILTERS(Transactions[Fund] = thisFund)
        )

 

 

 

3 Replies