Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago

Cannot apply VALUE on FILTERed table

Hello all,

 

Context

I have a table with a column named "Answer"

I want to measure the average of all numerical answer.

Because, see, some answer are numerical and some answer are textual, but because of that, they're all considered as "text" by default by Power BI.

 

Approach

To do so, I tried to:

  1. Filter the table
  2. Apply Value on the filtered table so I can only convert the numerical values to integer

Wich resulted in the following expresson:

 

 
measure = AVERAGEX ( FILTER(ALL(data) ; data[Type_Question] = "Numerical_Question" )      ;     VALUE([Answer])   ) 
 
I get the following error when applying this formula:
dax cannot convert value '' of type text to type integer
 
It seems like the Value function doesn't apply only on the rows of my filtered table which contains only numerical values (formatted as text) but on all the , but on ALL  the rows of the data table.
 
How can I prevent the function from doing so?
 
I want to FILTER then convert with VALUE on the filtered rows.
 
Regards,
 
 

9 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    can you post some sample data?  Sounds like it would be much easier to these transformations in Power Query and then write some simple dax...

  • v-danhe-msft's avatar
    v-danhe-msft
    Microsoft Employee

    Hi Anonymous,

    Based on test, it may caused by the null value in your data, you could refer to below steps:

    Sample data:

    Create below measure:

    measure = AVERAGEX ( FILTER(ALL(data),data[Type_Question] = "Numerical_Question"&&'data'[Answer]<>BLANK()), VALUE([Answer]))

    Result:

    You could also download the pbix file to have a view.

     

    Regards,

    Daniel He

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello Daniel,

       

      thank you for your answer, but it is still not working.

      You are right, I suspected some null values here, because there are.. but I know for sure that the condition in my filter is sufficient to filter out all non numerical value.

      Nevertheless, I tried your condition and I still get the same error.

       

      To me, the problem is that the VALUE() function doesn't apply only on the filtered values (no matter the condition stated), but to all rows of my 'data' table..

      How can I refer to my filtered table instead?

       

      something like :

      VALUE(data_filtered[Answer])

       

      You see my point?

      • v-danhe-msft's avatar
        v-danhe-msft
        Microsoft Employee

        Hi Anonymous,

        Could you please share some sample data to have a test?

         

         

        Regards,

        Daniel He