简体   繁体   中英

Date difference between pairs of dates per ID

I have data with 2 columns, in the following format:

ID Date
1 1/1/2020
1 27/7/2020
1 15/3/2021
2 18/1/2020
3 1/1/2020
3 3/8/2020
3 18/9/2021
2 23/8/2020
2 30/2/2021

Now I would like to create a calculation field in Tableau to find per ID the difference between the different dates. For any value eg days.

For example for ID 1 the difference of the two dates according to calendar is 208 days. Next the difference of the second to third date for the same ID is 231 days.

A table calc like the following should do if you get the partitioning, addressing and ordering right — such as setting “compute using” to Date.

If first() < 0 then min([Date]) - lookup(min([Date]), -1) end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM