Forum Discussion

Xerovoid's avatar
Xerovoid
Frequent Visitor
8 years ago
Solved

Measure formula using SUMX, FILTER and MAX/MIN

I am trying to better understand contexts with different formulas and I noticed a very strange behaviour. I created a random set of data to play with and when evaluating the below formula for measure...
  • Xerovoid's avatar
    Xerovoid
    8 years ago

    Hey Herbet, thank you for your feedback. I appreciate it as it helps me better understand how the DAX language is functioning under the hood.

     

    While I cannot dispute your solution provides the required results I still have concerns. While I cannot dispute your solution provides the required results I still have concerns.

     

    The programmer in me screams loudly at the repetative nature trying to force the language to do what I thought it should be doing in the first place. To me it feels like a calculator that does not correctly multiple two numbers so the solution is to just solve it using addition (imagine calculating 4027 * 1024 in such a way).

     

    I was under the impression that the SUMX(<table>, <expression>) function would evaluate the <expression> using the provided <table> much the same way that the CALCULATE(<expression>,<filter1>,<filter2>…)  function does.

     

    Knowing this now I could reduce the context going into SUMX() and the only way to do that would be to leverage CALCULATE(). The reason I would prefer this method is when you get into complicated filters in real world examples that start to create very complex formulas.

     

    MeasureMax = CALCULATE( SUMX( Table1 , MAX([Value]) ) , FILTER(Table1, Table1[Category] = "c") )
    MeasureMin = CALCULATE( SUMX( Table1 , MIN([Value]) ) , FILTER(Table1, Table1[Category] = "c") )

    Maybe I have misunderstood how the <expression> is being handled in terms of column based functions, I wonder if ruthpozuelo might be willing to comment as an MVP?