简体   繁体   中英

Calculate difference in days between two dates with conditions

I need help calculating the difference in two dates if certain criterias are met.

When One is 1 calculate the difference between the date of that value with the date when Move is 1 for each unique values of Person . When the difference in days are calculated, check for the next 1 in One , and so on. When One and Move have 1 in the same row, the value should be 0 (as seen in 14.01.2018). Notice the value in 05.01.2018, value 3 takes the date from 03.01.2018 (not 02.01.2018), as it is the last one if there are leading 1 's.

The expected values are in Days in bold and red:

在此处输入图片说明

I have been trying to do this for days in Python programming software, but without success. Any help is appreciated.

Assuming that your description regarding the date in 05.01.2018 is correct, and your screenshot is incorrect, then try:

E2: =IF(AND($C2=1,$D2=1),0,IF($C2=1,$A2-AGGREGATE(14,6,1/(($D$1:$D2=1)*($B$1:$B2=$B2))*$A$1:$A2,1),0))

and fill down.

Use conditional formatting to set the values > 0 to bold/red.

在此处输入图片说明

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