Forum Discussion

Dineshja48's avatar
Dineshja48
Copper Contributor
May 31, 2023
Solved

Finding error while calculate median for a Groupby - array returns zero with other values.

I'm trying to calculate a median value at group by operation but not finding correct answer. In my example i've material and plant information and want to know the total spend median value at each material and plant. 
For. eg.

MaterialPlantVendorTotal Spend Impact
11059512XA1127060
11059512XA112225000
11059512XA11113842
11059512XA1173800
11059512XA1141400
11514445YE0230236
11514445YE0230177
11532719YE0288243
67422090YR01103047
67422090Y50552356103047

Formula =MEDIAN((D2:D11)*--(A2:A11=A2)*--(B2:B11=B2))

I'm trying to execute this formula but it evaluate result it returns an array: median({27060:2225000:113842:73800:41400:0:0:0:0:0)}.
Since it is also considering 0 to calculate median, answer is coming wrong. How do I remove zero from my array list and only consider number.


 

  • Dineshja48 

    Try

     

    =MEDIAN(IF(($A$2:$A$11=A2)*($B$2:$B$11=B2),$D$2:$D$11))

     

    If you don't have Microsoft 365 or Office 2021, confirm the formula by pressing Ctrl+Shift+Enter

6 Replies

  • SergeiBaklan's avatar
    SergeiBaklan
    Diamond Contributor

    Dineshja48 

    As variant

    =AGGREGATE(17,6, D2:D11/($A$2:$A$11=A2)/($B$2:$B$11=B2), 2)

    used as regular formula on pre-DA Excel.

    • Dineshja48's avatar
      Dineshja48
      Copper Contributor

      SergeiBaklan  Thanks for helping to calculate Median. Could you also tell me if the aggregate function can also work for sum, average, count, etc with group by operation?
      I'm trying for sum but getting error..

      =AGGREGATE(9,6,$D$2:$D$11/(($A$2:$A$11=A2)*($B$2:$B$11=B2)))

      Thanks in advance! 🙂

      • SergeiBaklan's avatar
        SergeiBaklan
        Diamond Contributor

        Dineshja48 

        No, AGGREGATE() works with arrays only starting from function #14. All functions before work only with ranges.

  • Dineshja48 

    Try

     

    =MEDIAN(IF(($A$2:$A$11=A2)*($B$2:$B$11=B2),$D$2:$D$11))

     

    If you don't have Microsoft 365 or Office 2021, confirm the formula by pressing Ctrl+Shift+Enter

Resources