7 Replies Latest reply on Jan 28, 2016 6:55 PM by Mathew Grimm

# Flag for First Order From Customer

Given a dataset that has...

• customer_id
• order_id
• date
• amount

...what's the most efficient way for Tableau to handle a flag on a particular record that indicates it was the first order from a customer?

An example task would be wanting to count the number of new customers so far this year.

For example...

Customer_ID, Order_ID, Date, Amount, First_Order?

1, 100, 1/1/2016, \$10, Yes

1, 101, 1/2/2016, \$10, No

2, 102, 1/3/2016, \$10, Yes

3, 103, 1/4/2016, \$10, Yes

3, 104, 1/5/2016, \$10, No

etc.

Thanks!

Mathew

• ###### 1. Re: Flag for First Order From Customer

Hi Mathew-

Create an LOD function.

First Order

IF Date = {Fixed [Customer ID] : MIN([Date])} THEN "Yes" ELSE "No" END

9.2.2 workbook attached.  Thanks.

2 of 2 people found this helpful
• ###### 2. Re: Flag for First Order From Customer

Oh, I assumed he didn't have the flag yet.  Thanks Shawn.

• ###### 3. Re: Flag for First Order From Customer

Thanks, Shawn! Sorry for not making it clearer that a field like "First_Order" is not in my dataset, but should be able to be calculated from the data I do have.

• ###### 4. Re: Flag for First Order From Customer

Oh, then my example works to determine your flag.  Or replace the yes/no with 1/0  and you can sum it with Shawn's formula.

• ###### 5. Re: Flag for First Order From Customer

Thanks, Adam! Perhaps it's because I have a million records here, but it's having a devil of a time executing the query when placed on the filter shelf.

• ###### 6. Re: Flag for First Order From Customer

Are you already working off an extract?  Have you optimized it?

The LOD calc will not materialize into the extract with the optimize option though.

1 of 1 people found this helpful
• ###### 7. Re: Flag for First Order From Customer

An extract definitely helped performance! Thank you!