在powerbi中的DAX中使用条件语句时发现错误

问题描述 投票:0回答:1

我想将一个名为“customer_age”的数值变量分类为“AgeGroup”。但是,当我在新措施中使用 switch 语句 时,它会给出一条消息:列 “Customer_age 未找到”在此输入图片描述

DAX 查询是:

AgeGroup = SWITCH( TRUE(), 'public cust_detail'[customer_age] < 30, "20-30", 'public cust_detail'[customer_age] >= 30 && 'public cust_detail'[customer_age] < 40, "30-40", 'public cust_detail'[customer_age] >= 40 && 'public cust_detail'[customer_age] < 50, "40-50", 'public cust_detail'[customer_age] >= 50 && 'public cust_detail'[customer_age] < 60, "50-60", 'public cust_detail'[customer_age] >= 60, "60+", "unknown" )
注意:数据是通过本地主机上的 Postgres SQL 服务器导入到 power bi 的。

我想创建一个新的度量,将变量 customer_age 分类为 AgeGroup

powerbi conditional-statements switch-statement dax dashboard
1个回答
0
投票
我认为你正在制定一项措施。您可以尝试使用此 DAX 创建计算列

enter image description here

如果你可以创建一个措施,试试这个

AgeGroup = SWITCH( TRUE(), max('public cust_detail'[customer_age]) < 30, "20-30", max('public cust_detail'[customer_age]) >= 30 && max('public cust_detail'[customer_age]) < 40, "30-40", max( 'public cust_detail'[customer_age] )>= 40 && max('public cust_detail'[customer_age]) < 50, "40-50", max( 'public cust_detail'[customer_age] )>= 50 && max('public cust_detail'[customer_age]) < 60, "50-60", max('public cust_detail'[customer_age]) >= 60, "60+", "unknown" )
    
© www.soinside.com 2019 - 2024. All rights reserved.