英文:
Network days function in excel
问题
在Excel中,我想在另一个工作表上使用NETWORKDAYS
函数。
这是我正在使用的公式。Details
是表格名称
=NETWORKDAYS(Details[Date1],Details[Date2])
这个公式返回了一个#Value!
错误。
如何在NETWORKDAYS
函数中使用表格名称?
英文:
In Excel, I want to use the NETWORKDAYS
function on a table in another sheet.
This is the formula I am using. Details
is the table name
=NETWORKDAYS(Details[Date1],Details[Date2])
The formula is returning a #Value!
error.
How can I use a table name in the NETWORKDAYS
function?
答案1
得分: 1
源数据:Range vs Array
根据barry houdini的被接受答案,这个问题,NETWORKDAYS函数接受arrays
作为参数,但不接受ranges
。我已经测试并确认这是正确的。
这解释了为什么您的公式失败,因为您尝试传递两个范围:Details[Date1]
和Details[Date2]
。如果您首先将这两个范围转换为数组,NETWORKDAYS将成功输出一个值数组。
将范围转换为数组非常简单,只需对每个范围添加零,或者将范围相乘或相除: +0
,*1
,或 /1
新公式
=NETWORKDAYS(Details[Date1]+0,Details[Date2]+0)
<sub>公式示例</sub><br>
[<img src="https://i.stack.imgur.com/1GCbd.png" width="500" />](https://i.stack.imgur.com/1GCbd.png "点击放大")
<sub>测试包含范围和数组的参数</sub><br>
[<img src="https://i.stack.imgur.com/4elJv.png" width="500" />](https://i.stack.imgur.com/fLduy.png "点击放大")
关于空单元格的说明
- 在上述公式中,空单元格被解释为零
- NETWORKDAYS将零解释为
1/0/1900
的数值等效项 - 日期
d
的数值等效项可以通过计算d
和1/0/1900
之间的天数来确定,后者等同于VALUE(d)
的等效项 - 因此,如果两个参数单元格都为空,则NETWORKDAYS将返回
0
,如果其中一个单元格为空,仍将返回一个数字(取决于哪个参数为零)。
解决方法
解决方法是将零值(空单元格)强制转换为错误
- 如果提供给它的任何参数是错误的,NETWORKDAYS将返回一个错误
- 将一个数字
n
的倒数除以它的倒数将返回n
,其中n<>0
,但如果n=0
,它将触发一个错误:1/(1/3)=3
但1/(1/0)=#DIV/0!
- IFERROR会传递非错误,但如果检测到错误,它将允许不同的结果。在下面的公式中,备选结果是空白,
""
,但它也可以轻松地是"缺少参数"
带解决方法的公式
=IFERROR(NETWORKDAYS(1/(1/Details[Date1]),1/(1/Details[Date2])),"")
多行版本
=IFERROR(
NETWORKDAYS(
1/(1/Details[Date1]),
1/(1/Details[Date2])),"")
英文:
Source Data: Range vs Array
According to barry houdini's accepted answer to this question , the NETWORKDAYS function accepts arrays
as arguments, but not ranges
. I have tested and confirmed this to be the case.
This explains why your formula is failing as you are you trying to pass in two ranges: Details[Date1]
and Details[Date2]
. If you first convert the two ranges to arrays, NETWORKDAYS will successfully output an array of values.
It is simple enough to convert the ranges to arrays by adding zero to each range, or multiplying or dividing the ranges by one: +0
, *1
, or /1
New Formula
=NETWORKDAYS(Details[Date1]+0,Details[Date2]+0)
<sub>Formula Example</sub><br>
[<img src="https://i.stack.imgur.com/1GCbd.png" width="500" />](https://i.stack.imgur.com/1GCbd.png "click to enlarge")
<sub>Testing arguments containing Ranges vs. Arrays</sub><br>
[<img src="https://i.stack.imgur.com/4elJv.png" width="500" />](https://i.stack.imgur.com/fLduy.png "click to enlarge")
Note About Blank Cells
- In the formulas above, blank cells are interpreted as zero
- NETWORKDAYS will interpret zero as the numeric equivalent of
1/0/1900
- The numeric equivalent of a date
d
can be determined by counting the number of days betweend
and1/0/1900
which is the equivalent ofVALUE(d)
- As a result, NETWORKDAYS will return
0
if both the argument cells are blank, and will still return a number if one of the cells is blank (positive or negative depending on which argument is zero).
Workaround
The workaround is to coerce zero values (blank cells) to an error
- NETWORKDAYS will return an error if either argument provided to it is an error
- Dividing one by the inverse of a number
n
will returnn
wheren<>0
but ifn=0
it will trigger an error:1/(1/3)=3
but1/(1/0)=#DIV/0!
- IFERROR will pass non-errors, but allow a different result if it detects an error. In the formula below the alternative result is blank,
""
, but it could easily be"Argument(s) Missing"
Formula with Workaround
=IFERROR(NETWORKDAYS(1/(1/Details[Date1]),1/(1/Details[Date2])),"")
Multi-Line Version
=IFERROR(
NETWORKDAYS(
1/(1/Details[Date1]),
1/(1/Details[Date2])),"")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论