DAX measure to sum only numeric values on string column with both numbers and strings

旧时模样 提交于 2020-12-08 02:54:39

问题


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.


回答1:


This is a terrible way to store data, but it is possible to do what you're asking.

Try this measure, for example,

= SUMX(FILTER(Table1, Table1[type]="number"), VALUE(Table1[units]))

The VALUE function converts the string to a numeric value and we only sum over the rows where the type is "number".




回答2:


The main problem is that SUM will never work on a column that is defined as being text. So for example if your column was only numbers, but the column defined as text then Measure:= SUM ( table[ units] ) would always error.

The only way to really do what you want would to be having the data in separate columns by type. Then having within a calculated measure which returns based on the column.



来源:https://stackoverflow.com/questions/50742315/dax-measure-to-sum-only-numeric-values-on-string-column-with-both-numbers-and-st

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!