MS Project中的嵌套语句 [英] Nested Statement in MS Project

查看:106
本文介绍了MS Project中的嵌套语句的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在MS Project中创建一个if和语句,我在Excel中工作。

I am trying to make an if and statement work in MS Project that I have working in Excel.

Excel中的公式(单元格G4 =持续时间)

Formula in Excel (cell G4=duration)

= IF(AND( G4> = 0,G4< = 20),5,IF(AND(G4→20,G4< 41),4,IF(AND(G4→40,G4< 61),3,IF(AND(G4→60 ,G4< 81),2,IF(G4> 81,1,"无效"))))))

=IF(AND(G4>=0,G4<=20),5,IF(AND(G4>20,G4<41),4,IF(AND(G4>40,G4<61),3,IF(AND(G4>60,G4<81),2,IF(G4>81,1,"invalid")))))

MS Project中的公式(仅返回5和0)

Formula in MS Project (only returning 5 and 0)

IIF([时间] GT; = 0," 5英寸,IIF([时间]< = 20," 5英寸,IIF([时间]→20," 4英寸;, IIF([时间] LT; 41," 4英寸,IIF([时间]→40," 3英寸,IIF([时间] LT; 61," 3英寸,IIF([时间]→60 ," 2英寸,IIF([时间]< 81," 2",IIf([Duration]> 81,""",invalid"))))))))))

IIf([Duration]>=0,"5",IIf([Duration]<=20,"5",IIf([Duration]>20,"4",IIf([Duration]<41,"4",IIf([Duration]>40,"3",IIf([Duration]<61,"3",IIf([Duration]>60,"2",IIf([Duration]<81,"2",IIf([Duration]>81,"1","invalid")))))))))

推荐答案

您的公式中有几个问题,例如使用第一个if:如果持续时间> = 0对于所有内容都是正确的,那么您将得到"5"。您根本没有使用Excel中的AND。

there are several issues in your formula, e.g. with the first if: If duration >= 0 is quite true for everything, so you will get "5". You did not use the AND from Excel at all.

另一个是[持续时间]的用法。此字段以分钟为单位重新显示持续时间。所以你需要使用因子480(分钟/天)来共同计算值。

Another one is the usage of [Duration]. This field is repersenting the duration in minutes. So you need to use factor 480 (minutes/day) for comapring values.

无论如何,嵌套的ifs真的很糟糕。所以我建议使用开关。 (Switch(condition1,result1,condition2,result2,...)第一次转换为true时,Switch会停止。所以我建议使用Number类型的字段:

Anyway, nested ifs are really bad to read. So I suggest to use switch. (Switch(condition1, result1, condition2, result2, ...) Switch will stop whenever a contition is true for the first time. So my suggestion for a field of type Number:

Switch ([持续时间]> = 0并且[持续时间]< = 20 * 480; 5; [持续时间]> 20 * 480并且[持续时间]< = 40 * 480; 4; [持续时间]> 40 * 480并且[持续时间]< = 61 * 480; 3; [持续时间]> 60 * 480和[持续时间]< = 80 * 480; 2;真; -20)

Switch([Duration]>=0 And [Duration]<=20*480;5;[Duration]>20*480 And [Duration]<=40*480;4;[Duration]>40*480 And [Duration]<=61*480;3;[Duration]>60*480 And [Duration]<=80*480;2;True;-20)

使用最后一部分(True; -20),如果没有满足先前的一个版本,这将给你-20,使用TRUE作为"所有其余部分"的条件。如果你使用的是文本类型的字段,你可以使用"无效"代替我的-20。

With the last part (True;-20), this will give you -20 if none of the previous contitions was met, using TRUE as condition for "all of the rest". If you are using a field of type text, you can use "invalid" instead of my -20.

这有帮助吗?

Barbara

Does that help?
Barbara


这篇关于MS Project中的嵌套语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆