DAX度量仅对具有数字和字符串的字符串列上的数字值求和 [英] DAX measure to sum only numeric values on string column with both numbers and strings

查看:283
本文介绍了DAX度量仅对具有数字和字符串的字符串列上的数字值求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆