我对IF cond有疑问。与&&(和)。
当我使用单条件条件时:
Column =
IF (
'For PwerBi'[Cert type for TAT] = "Midterm Routine"
&& INT ( 24 * 'For PwerBi'[TAT excluding weekends_holidays] ) > 8,
">8Hrs",
"NA"
)
我没有收到错误,输出就来了。
但是,当我添加一个IF条件时:
Column =
IF (
'For PwerBi'[Cert type for TAT] = "Midterm Routine"
&& INT ( 24 * 'For PwerBi'[TAT excluding weekends_holidays] ) < 8,
INT ( 24 * [TAT excluding weekends_holidays] ),
"NA"
)
它给我一个错误:
“产生变量数据类型的表达式不能用于定义 计算列。”
我不明白此错误的含义。为什么会出现?
这是我原来的DAX公式-
Column 2 = IF('For PwerBi'[Cert type for TAT]="MR" && INT(24*'For PwerBi'[TAT excluding weekends_holidays])>8,">8Hrs",
IF('For PwerBi'[Cert type for TAT]="MR" && INT(24*'For PwerBi'[TAT excluding weekends_holidays])<=8,FORMAT( INT ( 24 * [TAT excluding weekends_holidays] ), "0" ),
IF('For PwerBi'[Cert type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("00:30:00"),"<30Min",
IF('For PwerBi'[Cert type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("00:30:00") && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("01:00:00"),"30 Min - 1 Hr",
IF('For PwerBi'[Cert type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("01:00:00") && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("01:30:00"),"1 Hr - 1.5 Hr",
IF('For PwerBi'[Cert type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("01:30:00") && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("02:00:00"),"1.5 Hr - 2 Hr",
IF('For PwerBi'[Cert type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("02:00:00") && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("02:30:00"),"2 Hr - 2.5 Hr",
IF('For PwerBi'[Cert type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("02:30:00") && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("03:00:00"),"2.5 Hr - 3 Hr",
IF('For PwerBi'[Cert type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("03:00:00") && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("03:30:00"),"3 Hr - 3.5 Hr",
IF('For PwerBi'[Cert type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("03:30:00") && 'For PwerBi'[TAT excluding weekends_holidays]<TIMEVALUE("04:00:00"),"3.5 Hr - 4 Hr",
IF('For PwerBi'[Cert type for TAT]="MRR" && 'For PwerBi'[TAT excluding weekends_holidays]>=TIMEVALUE("04:00:00"),"> 4 Hr",
IF('For PwerBi'[Cert type for TAT]="Rnw" && INT(24*'For PwerBi'[TAT excluding weekends_holidays])<8,"< 8 Hrs",
IF('For PwerBi'[Cert type for TAT]="Rnw" && INT(24*'For PwerBi'[TAT excluding weekends_holidays])>=8 && INT(24*'For PwerBi'[TAT excluding weekends_holidays])<16,"8 - 16 hrs",
IF('For PwerBi'[Cert type for TAT]="Rnw" && INT(24*'For PwerBi'[TAT excluding weekends_holidays])>=16 && INT(24*'For PwerBi'[TAT excluding weekends_holidays])<24,"16 - 24 hrs",
IF('For PwerBi'[Cert type for TAT]="Rnw" && INT(24*'For PwerBi'[TAT excluding weekends_holidays])>=24 && INT(24*'For PwerBi'[TAT excluding weekends_holidays])<36,"24 hrs - 36 hrs",
IF('For PwerBi'[Cert type for TAT]="Rnw" && INT(24*'For PwerBi'[TAT excluding weekends_holidays])>=36 && INT(24*'For PwerBi'[TAT excluding weekends_holidays]),"36 hrs - 48 hrs",
IF('For PwerBi'[Cert type for TAT]="Rnw" && INT(24*'For PwerBi'[TAT excluding weekends_holidays])>=48,"> 48 hrs",
IF('For PwerBi'[Cert type for TAT]="NA","NA",INT(24*'For PwerBi'[TAT excluding weekends_holidays])))))))))))))))))))
答案 0 :(得分:1)
您的度量不能同时输出数字和文本。您必须选择一个。首先,两个结果都是文本。在第二个中,您的True
结果是一个数字,而您的False
结果是文本。
要解决此问题,您可以使用FORMAT
function将数字转换为文本:
Column =
IF (
'For PwerBi'[Cert type for TAT] = "Midterm Routine"
&& INT ( 24 * 'For PwerBi'[TAT excluding weekends_holidays] ) < 8,
FORMAT( INT ( 24 * [TAT excluding weekends_holidays] ), "0" ),
"NA"
)