我想将一个名为“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
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"
)