Find observations of an ID within a certain timeframe in the future in Tableau

102 views Asked by At

I have a dataset in Tableau that contains sales data listing each sale the company has had in the past year. Each customer has a unique ID, and many customers return. I'm trying to figure out how to create a calculated field in Tableau that gives a True | False answer to whether a given patient ID appears again in the dataset within a given timeframe (say, within six weeks of a given observation).

I've tried running it with LOOKUP, but I haven't been able to specify the increase in time effectively.

1

There are 1 answers

3
Bernardo On

This would be how I would approach it. Create two date parameters, start and end.

Then create a filter calc for the date.

[date] >= [param_date_start]
and
[date] <= [param_date_end]

Place this in the filter shelf set to TRUE.

Then create another parameter for your customer id and you can test for the existence of a customer id as follows.

max([customer_id] = [param_customer_id])

This will return true if there is at least one record where the customer_id equals the param_customer_id for the chosen dimensions and date range.

You could use this same approach to define a computed set, say the set of all products that were purchased by the customer in the specified date range, or the set of all patients that received a particular service. Just use this formula on the condition tab when defining the set.