是什么导致了 MS 项目自定义字段公式中 IIf 的这种行为?

What is Causing this Behavior in an IIf in a MS Project Custom Field Formula?

我不明白我从自定义字段公式中看到的行为——实际上是从两个试图做同样事情的公式中看到的。

我正在尝试创建一个自定义公式来标记任务是否与 任何 基线相关联。我认为如果有一个与任务相关的基线开始或基线#开始,那么这意味着,是的,有一个与任务相关的基线。因此,我创建了这个公式并将其用于任务级别的标志字段:

IIf([Baseline Start] <> "" Or [Baseline1 Start] <> "" Or [Baseline2 Start] <> "" Or [Baseline3 Start] <> "" Or [Baseline4 Start] <> "" Or [Baseline5 Start] <> "" Or [Baseline6 Start] <> "" Or [Baseline7 Start] <> "" Or [Baseline8 Start] <> "" Or [Baseline9 Start] <> "" Or [Baseline10 Start] <> "", True, False)

对我来说很简单。它“表示”如果 Baseline Start 不为空或 Baseline1 Start 不为空或任何其他 Baseline# Start 值不为空,则 return True,否则 return False。但正在发生的是它仅在第一个条件下起作用——[基线开始] <> ""。满足该条件的任务正在接收 True。满足其他条件的任务都收到 False,即使它们应该有 True。我不明白为什么。

如果我交换条件的顺序,以便首先测试另一个 Baseline# Start,则满足该条件,其余的将像以前一样被忽略。只有满足新交换的第一个条件的任务才会收到 True,其余收到 False,即使它们应该有 True。

我也尝试了这种嵌套内联 if 方法并收到了完全相同的结果:

IIf([Baseline1 Start] <> "", True, IIf([Baseline Start] <> "", True, IIf([Baseline2 Start] <> "", True, IIf([Baseline3 Start] <> "", True, IIf([Baseline4 Start] <> "", True, IIf([Baseline5 Start] <> "", True, IIf([Baseline6 Start] <> "", True, IIf([Baseline7 Start] <> "", True, IIf([Baseline8 Start] <> "", True, IIf([Baseline9 Start] <> "", True, IIf([Baseline10 Start] <> "", True, False)))))))))))

有什么想法吗?

这是由于 MS Project 的一个奇怪之处,如果该字段为“NA”(空白),它使用 4294967296(2 的 32 次方 - 1)。因此,相反,测试日期是否小于那个巨大的数字,例如 4/8/2064,它方便地存储为 60000。

[Baseline Start] < 60000 Or [Baseline1 Start] < 60000 Or [Baseline2 Start] < 60000 Or [Baseline3 Start] < 60000 Or [Baseline4 Start] < 60000 Or [Baseline5 Start] < 60000 Or [Baseline6 Start] < 60000 Or [Baseline7 Start] < 60000 Or [Baseline8 Start] < 60000 Or [Baseline9 Start] < 60000 Or [Baseline10 Start] < 60000

注意IIf公式是不必要的因为上面会直接return True or False.

参考:Working with Custom Field Formulas