Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Understanding the DAX Measure

Hallo all,   learning power bi und trying to understand how Earlier function works.   here is a small example with a following data set ID Value1 Value2 10 6 20 11 7 11 12 8 ...
  • mahoneypat's avatar
    6 years ago

    Good to see you are digging in to understand DAX with a simple example first.  One comment.  You used "measure" to describe what you put in a calculated column.  While both Measures and Calculated Columns contain DAX expressions, they are not interchangeable.  For example, the first variable in your expression (=Table1[Value1]) would return an error in a Measure.  Calculated Columns have row context so it knows to get the value on that row (a measure would expect that column to be aggregated somehow).

     

    I would encourage you to learn to write measures wherever possible, and only do Calculated Columns when you need something for the axis/category/legend of a visual, or for performance reasons.

     

    In any case, the FILTER() function will return only rows that return TRUE().  In your case, there are three conditions.  To pass all three, the iterated row (in FILTER()) has to

    1 - be a different row than the current one (ID <> index)

    2 - Value1 has to be less than the stored Value1

    and

    3 - Value2 has to be greater than the stored Value2

     

    For the 1st row, there are no rows with Value1 <6, so you get blank

    For the 2nd row, only ID 10 row meets all 3, so you get a result of 1.

    For the 3rd row, only the 2nd row meets all 3, so you get a result of 1

    For the 4th row,  there are no rows with Value2 >21, so you get blank (not sure why you show 0 there)

     

    If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

    Regards,

    Pat