简体   繁体   English

Excel IF 函数同时跨多行和多列

[英]Excel IF function across multiple rows and columns at the same time

I manage a student housing apartment building and have my rent roll within a excel document.我管理一栋学生公寓楼,并将我的房租记录在 Excel 文件中。 In my property, residents are able to lease at multiple rent levels (whole unit, room within unit, or bed within the room).在我的物业中,居民可以以多种租金水平出租(整个单元、单元中的房间或房间中的床)。 I am looking to be able count the number of "Vacant" rooms if both of the beds within the room are labeled "Vacant".如果房间内的两张床都标记为“空置”,我希望能够计算“空置”房间的数量。

Column C has the unit number C列有单元号

Column D has the room number D列有房间号

Column E has the bed number E列有床号

Column F has the resident's name F栏是居民姓名

Unit 923(C1) room1(D1) Top(E1) John Doe(F1) Bottom(E2) Vacant(F2) room2(D3) Top(E3) Vacant(F3) Bottom(E4) Vacant(F4) Unit 923(C1) room1(D1) 顶部(E1) John Doe(F1) 底部(E2) 空置(F2) room2(D3) 顶部(E3) 空置(F3) 底部(E4) 空置(F4)

In this case, unit 923 is a two bedroom unit with four beds (two in each room).在这种情况下,单元 923 是一个两卧室单元,有四张床(每个房间两张)。 Room 1 is partially occupied by John Doe and is therefore not available at the room level.房间 1 被 John Doe 部分占用,因此无法在房间级别使用。 Room 2 has both of the beds "Vacant", so it is available to be rented out at the room level.房间 2 有两张床“空置”,因此可以在房间级别出租。

Thanks in advance!提前致谢!

You can nest logic with AND and OR to figure it out:您可以使用 AND 和 OR 嵌套逻辑来弄清楚:

IF x AND y => true if both x and y are true IF x AND y => 如果 x 和 y 都为真,则为真

IF x OR y => true if either x or y are true IF x OR y => true 如果 x 或 y 为真

IF x AND (y OR z) => true if x is true and either y OR z is true IF x AND (y OR z) => true 如果 x 为真且 y OR z 为真

See here for some examples. 有关一些示例, 请参见此处 Here is a more formal explanation这是一个更正式的解释

I added an additional column G to contain the results of the IF function.我添加了一个额外的列 G 来包含 IF 函数的结果。 My final formula is:我的最终公式是:

=IF(AND(AND(F3="VACANT"),AND(F4="VACANT",AND(D4=""))),1,0) =IF(AND(AND(AND(F3="VACANT"),AND(F4="VACANT",AND(D4=""))),1,0)

I just add the new column's values for the number of available bedrooms.我只是为可用卧室的数量添加新列的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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