首页 > 解决方案 > IF 带有 &&(多个条件)变体数据类型错误

问题描述

我对 IF cond 有疑问。与 && (和)。

当我使用单个 if 条件时,例如:

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])))))))))))))))))))

标签: powerbidax

解决方案


您的度量不能同时输出数字和文本。你必须选择一个或另一个。在第一个度量中,两个结果都是文本。第二,你的True结果是一个数字,你的False结果是文本。

FORMAT要解决此问题,您可以使用以下函数将数字转换为文本:

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"
)

推荐阅读