Search code examples
powerbidaxpowerbi-desktopmeasure

Create a PowerBI measure to sum a text column


I have a column in my table that looks as follows

Table

Answer   Type
10     |  10
N/A    |   3
four   |   3
20     |  10
4      |  10
yes=1  |   3

I only want to sum the columns that have a type of 10

This is what I tried.

sum = CALCULATE(SUM('Table'[Answer]),filter('Table',Table[Type]=10))+0

I wanted the output to be a sum of 34, but I keep getting an error:

The function sum can not work with values string

I can not change the datatype of the column as I use the text for a different calculation.

Could some one advise how to achieve this?


Solution

  • You can try below code

    Only_int_sum =
    CALCULATE (
        SUMX ( 'Table', IFERROR ( VALUE ( 'Table'[Answer] ), 0 ) ),
        'Table'[Type] = 10
    )
    

    PFA screenshot for reference

    enter image description here