Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
SanderB
Frequent Visitor

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

1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community 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

 

View solution in original post

8 REPLIES 8
Mariusz
Community Champion
Community 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

 

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
Community Champion
Community 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

 

Hi @Mariusz,

I looks like the FIXED function does not work there.

It will only give zero's and the filters are not working anymore, even without dynamic reference.

FIXED(AVERAGE( RESULT[VALUE] ),4,1 ))
 
Mariusz
Community Champion
Community Champion

Hi @SanderB 

 

Can you give an example?

 

 

Best Regards,
Mariusz

Please feel free to connect with me.
Mariusz Repczynski

 

Measure that is working with the incorrect decimals:

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

powerbi1.png

Measure that is not working:

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 ) )

powerbi2.png

 

Values in table used

SampleNAMEVALUEPLACESU_RPT_VALUEMerged
1Component10.022< 0.05<0.05
1Component20.032< 0.06<0.06
1Component35.2925.295.29
1Component45.3525.355.35
1Component55.325.305.3
1Component61.020841.02081.0208

 

Thanks!

Sander

 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

 

It works! Corrected the column and it is perfect!

Thank you very much!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.