powerbi - 在 Power BI 中使用多个条件和表创建列
问题描述
我想根据 Power BI 中的其他一些表为产品列表创建一个列。table1
是我要调查的产品的完整列表,
table1
:
id product_name
1 xl1
2 xl2
3 s11
4 m11
...
我想city
基于另一个表 table2 创建一个列:
id product_name city
1 xl1 D
2 xl1 A
3 xl1 A
4 xl1 A
5 xl1 A
6 s11 B
7 s11 B
8 s11 B
9 m11 C
如果product_name
intable1
也找到 in table2
,则查找city
,如果只有一个值,则用该值填充新列,如果有两个值,则写 'both',如果product_name
找不到 in table2
,则写 'no value'
预期输出:
id product_name new_col
1 xl1 both (because city =D,A in table2)
2 xl2 no value
3 s11 B
4 m11 C
...
我应该如何在 Power BI 中解决此类问题?任何建议表示赞赏。
解决方案
您可以使用以下dax
措施来实现您的结果,因此当您知道product
出现在 1 个以上独特的城市时,它会返回两者并在有帮助的情况下接受解决方案:)
Column =
var result1 = CALCULATE(FIRSTNONBLANK(Table2[city],1),
FILTER(ALL(Table2),Table2[product_name] = EARLIER(Table1[product_name])))
var distint = CALCULATE(DISTINCTCOUNT(Table2[city]),
FILTER(ALL(Table2),Table2[product_name]=EARLIER(Table1[product_name])))
return
IF(distint>1,"both",IF(ISBLANK(result1),"no value",result1))
推荐阅读
- netbeans - 观察到 NetBeans IDE 12 和 IDE 11.3 之间的 print() v println() 差异
- android - Google Play 管理中心要求我在发布应用之前对其进行审核,但我无需采取任何其他步骤
- visual-studio - 这两个 Word 互操作程序集引用有什么区别?
- android - 无法验证从静态方法调用的方法
- cs50 - CS50 PSET2:根本无法弄清楚如何实现 isalpha 以便检查每个命令行参数
- flask - Flask Jinja 宏:如何在 URL_FOR 中有动态参数名称?
- javascript - 反应钩子到组件中的工具类
- vb.net - TcpClient.Client.Send() 和 TcpClient.GetStream.Write() 是否等效?
- javascript - 如何在每次页面刷新时运行对 Unsplash 的 GET 请求?
- javascript - Cypress new command definition reference