简体   繁体   中英

Excel COUNTIFS between two dates keep returning 0

I don't understand my formula output (output = 0)

=COUNTIFS(PROJET!$C$13:$C$29,">="&PLANNING!$B13&"/"&PLANNING!C$12&"/"&PLANNING!$I$11,PROJET!$D$13:$D$29,"<"&PLANNING!$B13&"/"&PLANNING!C$12&"/"&PLANNING!$I$11)

where

PLANNING!$B13 = 1
PLANNING!C$12 = June
PLANNING!$I$11 = 2022


PROJET!$C$13:$C$29 = 
17/05/2022
16/12/2022
17/05/2022
19/05/2022
01/06/2022
19/12/2022
17/05/2022
10/11/2022
01/09/2022
15/09/2022
01/12/2022
01/11/2022
05/12/2022
15/12/2022
19/12/2022
16/12/2022
19/12/2022

PROJET!$D$13:$D$29 = 
17/05/2022
16/12/2022
19/05/2022
19/06/2022
01/07/2022
26/12/2022
01/07/2022
11/11/2022
15/09/2022
15/11/2022
09/12/2022
01/11/2022
15/12/2022
16/12/2022
21/12/2022
16/12/2022
29/12/2022

I tried to replace

PLANNING!$B13&"/"&PLANNING!C$12&"/"&PLANNING!$I$11

with :

DATEVAL($B13&"/"&$C$12&"/"&I$11)

but this still return 0 why does this return 0 and not 3 ? what am I missing ? I highlight in red the date where the date is between (01/06/2022) 在此处输入图片说明

Your date criteria is not a date. But even when you convert it to a date (using DATEVAL which I assume is the same as the US English DATEVALUE ), You will still return 0 because you have no rows that match both conditions of C >= 1/jun/2022 and D<1/jun/2022

To get a result of 3, you could change your comparisons around:

=COUNTIFS(PROJET!$C$13:$C$29,"<="&DATEVALUE(PLANNING!$B13&"/"&PLANNING!C$12&"/"&PLANNING!$I$11),
          PROJET!$D$13:$D$29,">"&DATEVALUE(PLANNING!$B13&"/"&PLANNING!C$12&"/"&PLANNING!$I$11))

在此处输入图片说明

Of course, I don't know if that's what you really want.

I think the way you are defining dates doesn't work. You can't paste together "1" "/" "June" and "2022" and have excel compare that to a date, unless I'm totally misunderstanding what you're trying to do. Here's an a simple example I cooked up:

Sample Criteria

With Formula showing

The #1 there calculates the number of dates in between 4/1/2021, and 3/1/2021. The formula I used was this: =COUNTIFS(B12:B15,"<="&DATE(2021,3,1),B12:B15,">"&DATE(2021,2,1))

Basically, I think where you're going wrong is you're telling excel to compare "1/June/2022" as a STRING to the date format 1/June/2022. Hopefully that helps, try using the date function instead of what you have. So instead of this: ">="&PLANNING!$B13&"/"&PLANNING!C$12&"/"&PLANNING!$I$11,PROJET!$D$13:$D$29,

Try this

">=DATE(Planning!B13, PlanningC12, PlanningI11)"

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