10 Replies Latest reply on Feb 18, 2016 11:07 AM by Imran Akbar

    Table calculation using rank

    Imran Akbar

      Hi,

       

      I'm trying to translate some logic I have in SQL to Tableau.

       

      My schema is like this (table header and two rows):

       

      customer_id, date, A

      1, 2015-01-01, 5

      1, 2016-01-02, 6

       

      I want to calculate the value of A, for the first date of each customer.

       

      In SQL, I would do something like this:

      SELECT

      A,

      RANK() OVER (PARTITION BY customer_id ORDER BY date) AS rank

      ....

      QUALIFY rank=1

       

      In Tableau, I see there's a rank function, and I can specify to partition over customer_id.

      To look at just the first rank, would I just create a calculated field that says 'IF rank=1 THEN 1 ELSE 0 END' and filter on that being = to 1?

       

      thanks!