Tableau Calculate Date Difference

B.Mr.W.

I am working with some sales data that each transaction has multiple stages. say stage A, B, C, D...

In the perfect world, each transaction need to go to each stage and I want to calculate the difference the transaction stays at each stage.

Say the data might look like this:

transaction_id    stage    updated_date
1                 A        2015-01-01
1                 B        2015-01-02
1                 C        2015-01-05
1                 D        2015-01-06

I want something like:

transaction_id    stage    time_spent
1                 AB       1 day
1                 BC       3 days
1                 CD       1 day 

Then I will be able to analyze the time spent at each stage and look at the histogram or distribution. However, the only thing I can find is the function datediff.

Can anyone show me how to achieve this in Tableau?

Andrew LaPrise

You could try using LOOKUP() to compute the duration using the date in the previous row of your partition:

DATEDIFF('day', LOOKUP(ATTR([Updated Date]), -1), ATTR([Updated Date]))

Then to get your "AB" labels, use LOOKUP() again to fetch it from the previous row:

LOOKUP(ATTR([stage]), -1) + ATTR([stage])

To make a histogram with the fields, you can drag [stage] to Columns, followed by [stage label] (or whatever you choose to call that second calculated field we made). Drag [duration] (the first field we made) into Rows. Then right click "A" in your chart and click "Hide". It's important that you hide it rather than filter it out, because it still needs to be in your partition for the table calculations to work! Then right click on the [stage] pill in your Columns card and uncheck "Show Header".

It's important to note that if Stage C (for example) isn't present in your data, then you will end up with a "BD" in your histogram, so here's hoping your data's pristine.

Caveat - One cost of using table calculations like lookup() is that they only operate on aggregated query results, which means all the data rows in question have to be fetched from the database to the Tableau client or server. So if you have a large amount of data and only want to display summary results such as the min/avg/max time to complete each phase, then table calcs can be an expensive and complicated way to get those summary measures.

An alternative is to reshape your data and use row level calcs, aggregate calcs or LOD calcs -- all of which can be performed by a source database. That is often simpler to manage also.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calculate date difference in javascript

From Dev

How to calculate DATE Difference in PostgreSQL?

From Dev

Calculate date difference in weeks (Javascript)

From Dev

Calculate date difference of dataframe groups

From Dev

How to calculate Date difference in Hive

From Dev

How to calculate date difference in pyspark?

From Dev

Calculate date difference of dataframe groups

From Dev

Calculate the date difference everyday automatically

From Dev

Calculate date difference in days in Android

From Dev

Mariadb - calculate date difference in hour

From Dev

How to calculate percent difference for an aggregated measure in Tableau?

From Dev

How to calculate percent difference for an aggregated measure in Tableau?

From Dev

SQL Query to Calculate the Rolling Difference by Date

From Dev

Calculate time difference in 24 Hours format with date

From Dev

Calculate date difference between two dates

From Dev

Calculate difference between the date and time entered?

From Dev

Calculate exact date difference in years using SQL

From Dev

Calculate year from date difference in Oracle

From Dev

java.util.Date Calculate difference in days

From Dev

How to calculate difference of date using sql

From Dev

Calculate Date difference between two consecutive rows

From Dev

how to calculate the difference between 2 date in android?

From Dev

Calculate difference between the date and time entered?

From Dev

Calculate time difference in 24 Hours format with date

From Dev

SQL Query to Calculate the Rolling Difference by Date

From Dev

Calculate date difference between two dates

From Dev

PHP date difference calculate onlys for days

From Dev

Convert date difference to years to calculate age in MongoDB

From Dev

Calculate Date difference in LOGSTASH based on conditional text

Related Related

  1. 1

    Calculate date difference in javascript

  2. 2

    How to calculate DATE Difference in PostgreSQL?

  3. 3

    Calculate date difference in weeks (Javascript)

  4. 4

    Calculate date difference of dataframe groups

  5. 5

    How to calculate Date difference in Hive

  6. 6

    How to calculate date difference in pyspark?

  7. 7

    Calculate date difference of dataframe groups

  8. 8

    Calculate the date difference everyday automatically

  9. 9

    Calculate date difference in days in Android

  10. 10

    Mariadb - calculate date difference in hour

  11. 11

    How to calculate percent difference for an aggregated measure in Tableau?

  12. 12

    How to calculate percent difference for an aggregated measure in Tableau?

  13. 13

    SQL Query to Calculate the Rolling Difference by Date

  14. 14

    Calculate time difference in 24 Hours format with date

  15. 15

    Calculate date difference between two dates

  16. 16

    Calculate difference between the date and time entered?

  17. 17

    Calculate exact date difference in years using SQL

  18. 18

    Calculate year from date difference in Oracle

  19. 19

    java.util.Date Calculate difference in days

  20. 20

    How to calculate difference of date using sql

  21. 21

    Calculate Date difference between two consecutive rows

  22. 22

    how to calculate the difference between 2 date in android?

  23. 23

    Calculate difference between the date and time entered?

  24. 24

    Calculate time difference in 24 Hours format with date

  25. 25

    SQL Query to Calculate the Rolling Difference by Date

  26. 26

    Calculate date difference between two dates

  27. 27

    PHP date difference calculate onlys for days

  28. 28

    Convert date difference to years to calculate age in MongoDB

  29. 29

    Calculate Date difference in LOGSTASH based on conditional text

HotTag

Archive