powerbi - 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])))))))))))))))))))
解决方案
您的度量不能同时输出数字和文本。你必须选择一个或另一个。在第一个度量中,两个结果都是文本。第二,你的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"
)
推荐阅读
- java - 如何在 PIE 下使用私有创建者(如 EGLContext)创建对象?
- node.js - Prerender 未检测到令牌请求
- swift - 如何为 NSFetchRequest 转换 T.Type?
- mysql - 如何将where子句变量放在选择查询的第一层
- typescript - object foo 有两个 props bar 和 baz ,如何通过 bar 的值推断 baz 类型
- excel - 在工作表 B 中存在的 B 列中的工作表 A 中的 A 列中查找值并更改颜色
- google-apps-script - Google Sheet Script Editor - 如果在数组中找不到选项卡名称,则删除多个选项卡的方法
- ajax - 将表格从 ajax 发送到 Django Rest 框架
- javascript - 从一个 json 文件创建多个 markdown 文件的脚本正在添加 http: 和 https: 前缀到链接。为什么?
- sql - 如何比较 2 个表并使用 1 个表中相似的数据返回一列