3 Replies Latest reply on Jan 10, 2014 3:23 PM by Joe Mako

    How to perform an Earlier function in Tableau

    alex macharia

      Richard Leeke Joe Mako

      I am trying to perform a calculation in tableau previously performed in powerpivot.

      Essentially the powerpivot formula uses the Earlier function. Do you have an idea for how to do this, below I have provided an elaboration of the earlier function.

      Flashback:   Simple Use of the EARLIER Function

      This is an excerpt from a post last month, “reprinted” here for convenience.

      Say I have the following VERY simple table like this:

      image

      And I want to add a third column that is the total for each customer:

      image

      The calc column formula for that third column is this:

      =CALCULATE(SUM([Amt]),
                 FILTER(ALL(‘Table’),
                   ‘Table’[Customer]=EARLIER(‘Table’[Customer])

                       )
                )

      Note the highlighted part:  in that formula we are filtering on ALL(Table) rather than just the “raw” Table.  Here’s the crux:

      When I say FILTER(ALL(Table)), all of my references to columns in Table will have “forgotten” all notion of “current row” and will instead be references to the entire column.  That is because of the ALL().

      So the EARLIER() function is my escape hatch that allows me to go back and inspect the current row’s value.

      This line of the formula:

        ‘Table’[Customer]=EARLIER(‘Table’[Customer])

      Can be understood as:

        ‘Table’[Customer]=CurrentRow(‘Table’[Customer])



      Source:The Correct Usage of EARLIER() « PowerPivotPro