Forum Discussion

SanderB's avatar
SanderB
Frequent Visitor
7 years ago
Solved

Avererage in column with variant data type

Hi all,

I am stuck in the matrix table in PowerBI.

See data below.

Column VALUE is formatted as numbers, TEXT as text and U_RPT_VALUE also as text.

TEST_NUMBERNAMEVALUETEXTU_RPT_VALUE
721195Component 10.10.1< 0.2
721178Component 100.0< 0.2
721188Component 24.334.334.33
721183Component 300.00< 5.9
721182Component 300.00< 5.9
721181Component 30.560.56< 5.9
721192Component 40DoneDone
721198Component 5755755755
721199Component 5730730730

Now I want to have a matrix table with the average of each component.

The problem is that because the column contains data and text you can only choose count, first etc

This will give the incorrect data for Component 5. 

 

So I created Measure = AVERAGE(Sheet2[VALUE]) but that will show incorrect values for component 3

I'm trying to build someting like:  If(U_RPT_VALUE contains < then show U_RPT_VALUE else (Measure = AVERAGE(Sheet2[VALUE]))

However, I cannot get it working due to the different data formats.

 

Do I make it myself to complicated and is there an easy way to accomplish this?

Thanks for the support!

Sander

  • Hi SanderB 

     

    Try the below

    Measure = 
    VAR _text = SELECTEDVALUE( 'Table'[U_RPT_VALUE] )
    VAR _search = SEARCH( "<", _text, 1, 0 ) > 0
    RETURN IF( _search, _text, AVERAGE( 'Table'[VALUE] ) )

     

    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    Mariusz Repczynski

     

8 Replies

  • Mariusz's avatar
    Mariusz
    Icon for Community Champion rankCommunity Champion

    Hi SanderB 

     

    Try the below

    Measure = 
    VAR _text = SELECTEDVALUE( 'Table'[U_RPT_VALUE] )
    VAR _search = SEARCH( "<", _text, 1, 0 ) > 0
    RETURN IF( _search, _text, AVERAGE( 'Table'[VALUE] ) )

     

    Best Regards,
    Mariusz

    If this post helps, then please consider Accepting it as the solution.

    Please feel free to connect with me.
    Mariusz Repczynski

     

    • SanderB's avatar
      SanderB
      Frequent Visitor

       Hi Mariusz ,

       

      Thank you very much, the use of a measure like that is totally new for me :-)

      It works perfect in the example, but on the complete database I get the "Expressions that yield variant data type" error. 

      This is caused by the Table[U_RPT_VALUE]

      There is a lot of data in this table, dates, <,>,negative numbers,-, text and empty

       

      Is there a way make this usefull? Otherwise I can create a new column and filter all the stuff out and see if it works

       

      • SanderB's avatar
        SanderB
        Frequent Visitor

        It works! Corrected the column and it is perfect!

        Thank you very much!

    • SanderB's avatar
      SanderB
      Frequent Visitor

      Hi Mariusz ,

       

      Only one small question about AVERAGE.

      Is it possible to have the decimal places dynamic?

      I thought that the FIXED function will do this, but this does not work.

       

      Measure = 
      VAR _text = SELECTEDVALUE( RESULT[Merged] )
      VAR _search = SEARCH( "<", _text, 1, 0 ) > 0
      RETURN IF( _search, _text, FIXED(AVERAGE(RESULT[VALUE]),(RESULT[PLACES]),1))

      Thanks,

      Sander 

       

      • Mariusz's avatar
        Mariusz
        Icon for Community Champion rankCommunity Champion

        HI SanderB 

         

        You need some form of aggregation around RESULT[PLACES], try MIN or MAX like below.

         

        Measure = 
        VAR _text = SELECTEDVALUE( RESULT[Merged] )
        VAR _search = SEARCH( "<", _text, 1, 0 ) > 0
        RETURN IF( _search, _text, FIXED( AVERAGE( RESULT[VALUE] ), MAX( RESULT[PLACES] ), 1 ) )
        Best Regards,
        Mariusz

        Please feel free to connect with me.
        Mariusz Repczynski