Forum Discussion

Sasha's avatar
Sasha
Helper III
7 years ago
Solved

A diff between a measure and its implicit definition

Hi,

As an example I have a table with Runs details where each row has a date, the number of a run and a specific km with its time.

I also have a measure Best_1_km = MIN(RunsDetails[Time]) showing the best km.

Now I want to find the date of the best km.

Why do these two formulas showing different results (the latter on shows the desired result while the first just shows the date of the first run)

 

Date_Best_1_km = CALCULATE(MIN(RunsDetails[Date]),FILTER(RunsDetails,RunsDetails[Time]=[Best_1_km])))

Date_Best_1_km = CALCULATE(MIN(RunsDetails[Date]),FILTER(RunsDetails,RunsDetails[Time]=MIN(RunsDetails[Time])))

 

I think it has something to do with context transition, just don't exactly understand what may be the cause.

 

Thanks

Alex

  • Sasha

     

    Actually MEASURE transforms a ROW context into Filter Context
    https://www.sqlbi.com/articles/understanding-context-transition/

    So in your case the MEASURE [Best_1_km] gets evlauated differently for every row of the RunsDetails Table

    If you store the MEASURE first in a variable and then apply this formula,, it will work

     

    Date_Best_1_km =
    VAR mybest = [Best_1_km]
    RETURN
        CALCULATE (
            MIN ( RunsDetails[Date] ),
            FILTER ( RunsDetails, RunsDetails[Time] = mybest )
        )
    

     

2 Replies

  • Zubair_Muhammad's avatar
    Zubair_Muhammad
    Community Champion

    Sasha

     

    Actually MEASURE transforms a ROW context into Filter Context
    https://www.sqlbi.com/articles/understanding-context-transition/

    So in your case the MEASURE [Best_1_km] gets evlauated differently for every row of the RunsDetails Table

    If you store the MEASURE first in a variable and then apply this formula,, it will work

     

    Date_Best_1_km =
    VAR mybest = [Best_1_km]
    RETURN
        CALCULATE (
            MIN ( RunsDetails[Date] ),
            FILTER ( RunsDetails, RunsDetails[Time] = mybest )
        )
    

     

    • Sasha's avatar
      Sasha
      Helper III

      Thank you!

      So there shouldn't be an issue with the second version I've wrote?