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
Anonymous
Not applicable

DAX: Unwanted cartesian product lines?

 

Please help to calculate/understand properly lastDate and rankDate measures for following simplified example (download) :

image.png

Desired result:

image.png

 

Reality (incorrect subtypes):

image.png

Why relationship is broken?

How to avoid this cartesian product lines?

 

My Measure (I commented workaround, because it's kind of postfilter, not prefilter):

rnkDate = 
VAR t =
    CALCULATETABLE(
        VALUES(tstTable[Date]),
        REMOVEFILTERS(tstTable[Date])
    )
RETURN 
    //IF( MAX(tstTable[Amount])<>BLANK(), // WORKAROUND To hide unwantedd rows
        RANKX(
            t,
            LASTDATE(tstTable[Date])
        )
    //)

P.S. Mess happens only if I use fields from dimensional table dimType[Type] (within one table everything is Ok):

image.png
3 REPLIES 3
Anonymous
Not applicable

@tamerj1 , thank you for your feedback.

  1. Regarding lastDate, as far as I understand crossfilter is not necessary. And here is more important question for me regarding this measure 
  2. Regarding rnkDate, the question is why it returns cartesian product for subTypes if we do NOT use if statement? Is it normal?
    NB! it's NOT about empty values, it's about CARTESIAN product
     DenisSipchenko_0-1673512532167.png

     

  3. A bit of topic: how do you attach .pbix direcctly in post? When I try drag&drop
    DenisSipchenko_0-1673512829208.png

     

@Anonymous 
1. Yes you are right. 

2. The issue is related to the filter context. One column of the fact table (the [Date] column) is used in the matrix therefore, it's part of the filter context. In this case the filter context created by the engine is the CROSSJOIN between the SUMMARIZE ( dimType, dimType[Type], dimType[subType] ) and DISTINCT ( tstTable[Date] ) which generates all the possible combinations between the two tables. 

When placing a normal aggregation measure in the matrix the engine checks first if the value is blank then it hides it. With RANKX things are different and the reason is that even the balnk value will have a rank (because DAX considers blank as zero in calculations) and the rank cannot be blank rather it will be the samllest or the largest rank value depending on the sort oreder of RANKX.

3. You can upload to DropBox or OneDrive and share the download link.

tamerj1
Super User
Super User

Hi @Anonymous 
Please refer to attached sample file with the solution 

1.png2.png

lastDate = 
CALCULATE (
    LASTDATE ( tstTable[Date] ),
    REMOVEFILTERS ( tstTable[Date] ),
    CROSSFILTER ( tstTable[subType], dimType[subType], BOTH )
)
rnkDate = 
VAR t =
    CALCULATETABLE (
        VALUES ( tstTable[Date] ),
        REMOVEFILTERS ( tstTable[Date] )
    )
VAR Result = 
    RANKX(
        t,
        CALCULATE ( MAX ( tstTable[Date] ) )
    )
RETURN
    IF ( 
        NOT ISEMPTY ( tstTable ),
        Result
    )

 

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.

Top Solution Authors