简体   繁体   中英

How to write a Countifs formula in Excel?

When I drag or copy the formula to another cell then the date should be changed. Every time I need to change the date manually.

Only date should change when I drag the formula as this is a monthly.

Example is given below.

=COUNTIFS($M$35:$M$1007,”=1/9/2018″,$N$35:$N$1007,”TS”,$O$35:$O$1007,”HP”,$P$35:$P$1007,”1″)
=COUNTIFS($M$35:$M$1007,”=2/9/2018″,$N$35:$N$1007,”TS”,$O$35:$O$1007,”HP”,$P$35:$P$1007,”1″)
=COUNTIFS($M$35:$M$1007,”=3/9/2018″,$N$35:$N$1007,”TS”,$O$35:$O$1007,”HP”,$P$35:$P$1007,”1″)

Use the DATE function to return a true date. The DATEVALUE function is an alternative but I prefer DATE. Don't quote numbers. Try not to use ambiguous DMY/MDY dates for examples. You don't need equals (eg = ) signs in a COUNTIFS.

Quoted strings do not change when dragged or copied to a new location. You need to include something that changes.

I've assumed a DMY date system. For 01-Sep-2018,

=COUNTIFS($M$35:$M$1007, date(2018, 9, row(1:1)), $N$35:$N$1007, "TS", $O$35:$O$1007, "HP", $P$35:$P$1007, 1) 

Fill down for 02-Sep-2018, 03-Sep-2018, etc.

Alternative for dragging across.

=COUNTIFS($M$35:$M$1007, date(2018, 9, column(a:a)), $N$35:$N$1007, "TS", $O$35:$O$1007, "HP", $P$35:$P$1007, 1) 

Be careful about putting 'smart quote' in your formulas. Your examples were littered with them and they don't work in formulas.

You would need to define the dates you care about in their own column, and then make sure that the reference to them is unlocked within the formula:

 'A'         'B'
|date_field| formula                                                 |
----------- ----------------------------------------------------------
| 1/9/2018 |=COUNTIFS($M$35:$M$1007,$A1,$N$35:$N$1007,"TS", ... etc) |
----------- ----------------------------------------------------------
| 2/9/2018 |=COUNTIFS($M$35:$M$1007,$A2,$N$35:$N$1007,"TS", ... etc) |
----------- ----------------------------------------------------------
| 3/9/2018 |=COUNTIFS($M$35:$M$1007,$A3,$N$35:$N$1007,"TS", ... etc) |
----------- ----------------------------------------------------------

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