Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powerbi 根据另一列中的字符串添加自定义列_Powerbi_Dax_Powerquery - Fatal编程技术网

Powerbi 根据另一列中的字符串添加自定义列

Powerbi 根据另一列中的字符串添加自定义列,powerbi,dax,powerquery,Powerbi,Dax,Powerquery,有没有办法评估投保设备的销售情况 Source data: Market Platform Web sales $ Mobile sales $ Insured FR iPhone 1323 8709 Y IT iPad 12434 7657 N FR android 234 2352355

有没有办法评估投保设备的销售情况

    Source data:

Market  Platform        Web sales $ Mobile sales $  Insured
FR      iPhone          1323        8709              Y
IT      iPad            12434       7657              N
FR      android         234         2352355           N
IT      android         12323       23434             Y

某种程度上,只是不确定如何处理它

对你的问题的直接回答是

if List.Contains({"iPhone","iPad","iPod"},[Platform]) and ([Insured]="Y") then [Mobile sales] else "error"
不过,我想强调几件事

首先,最好先将
[insurated]
列中的值转换为布尔值。这样,您就可以在错误损坏您的数据之前捕获错误,而不会引起您的注意。我的示例没有做到这一点,它所做的只是在
[Insured]
中否定字母大小写,因为PowerM是区分大小写的语言

其次,最好使用
null
而不是文本值错误。然后,您可以设置列类型,并对其值进行一些计算,例如求和。在混合文本和数字值的情况下,在这种情况和许多其他情况下,您将得到一个错误

最后。
使用透视表来可视化这样的数据可能是更好的方法。您只需添加一列,根据相同的逻辑将所有苹果(和/或其他)设备分组在一起,但不包括
[投保]
。Pivot表更灵活,我个人也非常喜欢它们。

建议的列在我看来是合理的,而不是混合数据类型。它出错了,但不确定如何正确地包含“和”上下文错误说明了什么?需要一个“then”if列表。包含({“iPhone”、“iPad”、“iPod”}、[Platform])和([受保]=“Y”)then“”else“error”)此代码正常工作,但所有结果都是错误(输出)
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    SumUpSales = Table.AddColumn(Source, "Sales of insured devices", each if List.Contains({"iPhone","iPad","iPod"}, _[Platform]) and Text.Upper(_[Insured]) = "Y" then _[#"Mobile sales $"] else null, type number)
in
    SumUpSales