DAX 度量仅对包含数字和字符串的字符串列上的数值求和 [英] DAX measure to sum only numeric values on string column with both numbers and strings
问题描述
如何创建 DAX 度量以仅对数值求和?假设我们有如下简单的样本数据.
How to create DAX measure to sum up only numeric values? Suppose we have simple sample data as below.
我认为这段代码可能会完成这项工作,但它失败了.
I thought that this code might do the job, but it failed.
m1 = IF( MAX(Table1[category]) = "apples", SUM(Table1[units]) , BLANK() )
当我尝试将此度量添加到仅对苹果和李子应用过滤器的表中时,我收到错误消息:
When I try to add this measure to the table, which has applied filters for apples and plums only, I get the error message:
我需要先应用过滤器,播种文本值,然后仅对数值进行汇总的东西.
I need something that will apply filter first, seeding out text values, then do the summing up on numeric values only.
推荐答案
这是一种糟糕的数据存储方式,但可以按照您的要求进行操作.
This is a terrible way to store data, but it is possible to do what you're asking.
试试这个措施,例如,
= SUMX(FILTER(Table1, Table1[type]="number"), VALUE(Table1[units]))
VALUE
函数将字符串转换为数值,我们只对 type
为数字"的行求和.
The VALUE
function converts the string to a numeric value and we only sum over the rows where the type
is "number".
这篇关于DAX 度量仅对包含数字和字符串的字符串列上的数值求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!