Forum Discussion

AlexisOlson's avatar
AlexisOlson
Super User
5 years ago
Solved

Understanding Context Transition with Table Filter Arguments

As a follow-up to this post, I've created a simpler example that demonstrates the core of the behavior I still don't quite understand.

 

Consider the following table, 'Data':

 

Data = DATATABLE ( "group", STRING, "amount", INTEGER, { {"A", 5}, {"A", 10}, {"B", 12}, {"C", 15} } )

 

 

I'd like to understand why the following do not give the same result:

 

SUMMARIZECOLUMNS (
    Data[group],
    "Rank", RANKX ( ALL ( Data[group] ), CALCULATE ( SUM ( Data[amount] ) ) )
)

 

versus

 

SUMMARIZECOLUMNS (
    Data[group],
    Data,
    "Rank", RANKX ( ALL ( Data[group] ), CALCULATE ( SUM ( Data[amount] ) ) )
)

 

The first gives A,B,C with Rank 2,3,1 respectively, whereas the second gives Rank 1,1,1.

 

Similarly, the following also return different results (which match the results above):

 

ADDCOLUMNS (
    VALUES ( Data[group] ),
    "Rank",
        CALCULATE (
            RANKX ( ALL ( Data[group] ), CALCULATE ( SUM ( Data[amount] ) ) )
        )
)

 

versus

 

ADDCOLUMNS (
    VALUES ( Data[group] ),
    "Rank",
        CALCULATE (
            RANKX ( ALL ( Data[group] ), CALCULATE ( SUM ( Data[amount] ) ) ),
            Data
        )
)

 

 

Curiously, if I replace RANKX with SUMX in the ADDCOLUMNS pair of expressions, the results match each other (both give A,B,C with Rank 47,47,47) whereas the SUMMARIZECOLUMNS pair gives A,B,C with Rank 47,47,47 for the first expression but Rank 15,12,20 for the second one.

 

These examples are a bit contrived but I'm looking to understand exactly why these behave the way they do and this was the most simplified form I could come up with. They may look slightly less odd if you replace CALCULATE ( SUM ( Data[amount] ) ) with a  measure [SumAmount] := SUM ( Data[amount] ).

 

What's going on here? How is the table argument getting applied in these cases?

6 Replies

    • AlexisOlson's avatar
      AlexisOlson
      Super User

      Thanks. Auto-Exists does seem like the likely explanation, at least for the SUMMARIZECOLUMNS cases since using a dimension table for group resolves the issue.

       

      For the ADDCOLUMNS examples, using a dimension table doesn't seem to help so maybe there's something else happening. Auto-Exists also doesn't explain why RANKX and SUMX behave differently for these. 

      • edhans's avatar
        edhans
        Community Champion

        I'm certianly not an expert in Auto-Exists, but I believe it returns a table with specific info, therefore SUMX and RANKX are operating on a different result set than the SUMMARIZECOLUMNS without the filter table. That is why you are getting different results. SQLBI does a deep dive into Auto Exist in this video.

        If you could mark one or more of these as the solution so this thread can be marked solved, we'd appreciate it.