+ Reply to Thread
Results 1 to 40 of 40

minimum along rows:creates an array

  1. #1
    Harlan Grove
    Guest

    re: minimum along rows:creates an array

    [email protected] wrote...
    ....
    >>=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >>COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >>0,1,COLUMNS(Rng)),Rng&""))

    >
    >So far I think it creates an array the size of the range that identifies
    >(1 or 0) the lowest number (or if n multiples uses a fraction 1/n)
    >This is then Sumproducted with the original array.
    >
    >Please could you explain how the two COUNTIF(OFFSET()) functions are
    >constructed and how they work


    The key is the OFFSET calls. They return what are effectively arrays of
    range references, in this case arrays of references to each row in Rng.
    That's due to the 2nd argument which evaluates to an array of serial
    numbers from 0 to N-1 where N is the number of rows in Rng. COUNTIF,
    SUMIF, N and T seem to be the only functions that can handle such
    arrays. COUNTIF and SUMIF return array results as if their (scalar)
    criteria argument had been applied to each range in the array of range
    references.

    The first COUNTIF call returns an array of nonnegative numbers in which
    zero corresponds to the max value (the value for which there are no
    values strictly larger). The equality test after boolean to numeric
    conversion then has ones for max values and zeros for smaller values.
    The second COUNTIF call in the denominator returns the number of max
    values.

    As for the interaction of OFFSET-generated arrays of ranges and an
    array criteria argument to COUNTIF, it seems to work when the arrays
    conform. The return value is the same size as the criteria argument and
    is equivalent to applying each separate range to the entire criteria
    array.


  2. #2

    re: minimum along rows:creates an array

    Harlan
    thanks for taking the time to explain this.
    there are a few new elements for me to use. My initial efforts to solve
    the op's question had lead me down OFFSET with an array call. However, as
    you point out, MIN does not work.
    Therefore, I now understand the use of the two COUNTIFs to mimic this
    action.
    I did solve the problem with a brute force UDF but I do like the idea of
    using worksheet functions when I can.


  3. #3

    minimum along rows:creates an array

    Harlan
    I have tried to work out how your formula works and am struggling

    >=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >0,1,COLUMNS(Rng)),Rng&""))


    So far I think it creates an array the size of the range that identifies
    (1 or 0) the lowest number (or if n multiples uses a fraction 1/n)
    This is then Sumproducted with the original array.

    Please could you explain how the two COUNTIF(OFFSET()) functions are
    constructed and how they work

    many thanks
    RES

  4. #4
    Harlan Grove
    Guest

    re: minimum along rows:creates an array

    [email protected] wrote...
    ....
    >>=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >>COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >>0,1,COLUMNS(Rng)),Rng&""))

    >
    >So far I think it creates an array the size of the range that identifies
    >(1 or 0) the lowest number (or if n multiples uses a fraction 1/n)
    >This is then Sumproducted with the original array.
    >
    >Please could you explain how the two COUNTIF(OFFSET()) functions are
    >constructed and how they work


    The key is the OFFSET calls. They return what are effectively arrays of
    range references, in this case arrays of references to each row in Rng.
    That's due to the 2nd argument which evaluates to an array of serial
    numbers from 0 to N-1 where N is the number of rows in Rng. COUNTIF,
    SUMIF, N and T seem to be the only functions that can handle such
    arrays. COUNTIF and SUMIF return array results as if their (scalar)
    criteria argument had been applied to each range in the array of range
    references.

    The first COUNTIF call returns an array of nonnegative numbers in which
    zero corresponds to the max value (the value for which there are no
    values strictly larger). The equality test after boolean to numeric
    conversion then has ones for max values and zeros for smaller values.
    The second COUNTIF call in the denominator returns the number of max
    values.

    As for the interaction of OFFSET-generated arrays of ranges and an
    array criteria argument to COUNTIF, it seems to work when the arrays
    conform. The return value is the same size as the criteria argument and
    is equivalent to applying each separate range to the entire criteria
    array.


  5. #5

    re: minimum along rows:creates an array

    Harlan
    thanks for taking the time to explain this.
    there are a few new elements for me to use. My initial efforts to solve
    the op's question had lead me down OFFSET with an array call. However, as
    you point out, MIN does not work.
    Therefore, I now understand the use of the two COUNTIFs to mimic this
    action.
    I did solve the problem with a brute force UDF but I do like the idea of
    using worksheet functions when I can.


  6. #6

    re: minimum along rows:creates an array

    Harlan
    I have tried to work out how your formula works and am struggling

    >=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >0,1,COLUMNS(Rng)),Rng&""))


    So far I think it creates an array the size of the range that identifies
    (1 or 0) the lowest number (or if n multiples uses a fraction 1/n)
    This is then Sumproducted with the original array.

    Please could you explain how the two COUNTIF(OFFSET()) functions are
    constructed and how they work

    many thanks
    RES

  7. #7

    re: minimum along rows:creates an array

    Sorry for misleading, the first column indicate the row number.
    Simply, I rewrite it as follows:

    A B
    5 6
    2 0
    1 3
    : :

    Expected result: 5 + 0 + 1 + ...

    Bruno Campanini =E5=AF=AB=E9=81=93=EF=BC=9A

    > <[email protected]> wrote in message
    > news:[email protected]...
    > > Hi,
    > > Is it possible to sum up the minimums of each row in one line commmand?
    > > E.g.
    > > A B
    > > 1 5 6
    > > 2 2 0
    > > 3 1 3
    > > Ans: 5 + 0 + 1
    > > I've tried
    > > {=3Dsum(min(a1:a3,b1:b3))}
    > > but it doesn't work.
    > > Thanks

    >
    > You have 2 numbers in column A and one in B.
    > Why Ans: 5 + 0 + 1?
    > Shouldn't be 1 + 0 + 1?
    >=20
    > Bruno



  8. #8
    dtb
    Guest

    re: minimum along rows:creates an array

    Try this:
    =SUM(MIN(A1:B1),MIN(A2:B2),MIN(A3:B3))
    --
    Regards,
    db

  9. #9
    Bruno Campanini
    Guest

    re: minimum along rows:creates an array

    <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    > Is it possible to sum up the minimums of each row in one line commmand?
    > E.g.
    > A B
    > 1 5 6
    > 2 2 0
    > 3 1 3
    > Ans: 5 + 0 + 1
    > I've tried
    > {=sum(min(a1:a3,b1:b3))}
    > but it doesn't work.
    > Thanks


    You have 2 numbers in column A and one in B.
    Why Ans: 5 + 0 + 1?
    Shouldn't be 1 + 0 + 1?

    Bruno



  10. #10

    re: minimum along rows:creates an array

    Harlan
    thanks for taking the time to explain this.
    there are a few new elements for me to use. My initial efforts to solve
    the op's question had lead me down OFFSET with an array call. However, as
    you point out, MIN does not work.
    Therefore, I now understand the use of the two COUNTIFs to mimic this
    action.
    I did solve the problem with a brute force UDF but I do like the idea of
    using worksheet functions when I can.


  11. #11

    re: minimum along rows:creates an array

    I have tried a few formula options with no luck
    however if a UDF would help

    Function SumMin(myInfo As Range) As Double
    Dim RowCount As Integer
    Dim i As Integer
    SumMin = 0
    RowCount = myInfo.Rows.Count
    For i = 1 To RowCount
    SumMin = SumMin + WorksheetFunction.Min(myInfo.Rows(i))
    Next i
    End Function

    As with much of my work it feels like brute force but seems to do the job
    <g>

    if you need a primer on UDFs then
    http://www.mvps.org/dmcritchie/excel/getstarted.htm
    is a good place to start

    hth RES

  12. #12
    Bruno Campanini
    Guest

    re: minimum along rows:creates an array

    <[email protected]> wrote in message
    news:eU6%[email protected]...
    >I have tried a few formula options with no luck
    > however if a UDF would help
    >
    > Function SumMin(myInfo As Range) As Double
    > Dim RowCount As Integer
    > Dim i As Integer
    > SumMin = 0
    > RowCount = myInfo.Rows.Count
    > For i = 1 To RowCount
    > SumMin = SumMin + WorksheetFunction.Min(myInfo.Rows(i))
    > Next i
    > End Function
    >
    > As with much of my work it feels like brute force but seems to do the job


    Yes, it works fine!
    My bruter force would omit SumMin = 0

    Bye
    Bruno



  13. #13
    Harlan Grove
    Guest

    re: minimum along rows:creates an array

    [email protected] wrote...
    >Is it possible to sum up the minimums of each row in one line commmand?
    >
    >E.g.
    >
    > A B
    >1 5 6
    >2 2 0
    >3 1 3
    >
    >Ans: 5 + 0 + 1

    ....

    The simplest way to handle your example data (or any 2-column
    comparison) would be to use an array formula like

    =SUM(IF(A1:A3<B1:B3,A1:A3,B1:B3))

    Getting exotic, if you wanted the sum of the minimum values from each
    row in the multiple (>2) column range Rng, you could use a formula like

    =SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    0,1,COLUMNS(Rng)),Rng))


  14. #14
    Bruno Campanini
    Guest

    re: minimum along rows:creates an array

    "Harlan Grove" <[email protected]> wrote in message

    > The simplest way to handle your example data (or any 2-column
    > comparison) would be to use an array formula like
    >
    > =SUM(IF(A1:A3<B1:B3,A1:A3,B1:B3))
    >
    > Getting exotic, if you wanted the sum of the minimum values from each
    > row in the multiple (>2) column range Rng, you could use a formula like
    >
    > =SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    > COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    > 0,1,COLUMNS(Rng)),Rng))


    The second formula doesn't work with me; I get #DIV/0!
    What's wrong?

    Bruno




  15. #15
    Harlan Grove
    Guest

    re: minimum along rows:creates an array

    Bruno Campanini wrote...
    >"Harlan Grove" <[email protected]> wrote in message

    ....
    >>=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >>COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >>0,1,COLUMNS(Rng)),Rng))

    >
    >The second formula doesn't work with me; I get #DIV/0!
    >What's wrong?


    If you have any blank cells in Rng, you'd need to change the formula to

    =SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    0,1,COLUMNS(Rng)),Rng&""))


  16. #16
    Bruno Campanini
    Guest

    re: minimum along rows:creates an array

    "Harlan Grove" <[email protected]> wrote in message
    news:[email protected]...
    > Bruno Campanini wrote...
    >>"Harlan Grove" <[email protected]> wrote in message

    > ...
    >>>=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >>>COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >>>0,1,COLUMNS(Rng)),Rng))

    >>
    >>The second formula doesn't work with me; I get #DIV/0!
    >>What's wrong?

    >
    > If you have any blank cells in Rng, you'd need to change the formula to
    >
    > =SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    > COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    > 0,1,COLUMNS(Rng)),Rng&""))


    I didn't have any blank cells in Rng.
    But now the new formula works fine.

    Many thanks
    Bruno



  17. #17

    re: minimum along rows:creates an array

    Harlan
    I have tried to work out how your formula works and am struggling

    >=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >0,1,COLUMNS(Rng)),Rng&""))


    So far I think it creates an array the size of the range that identifies
    (1 or 0) the lowest number (or if n multiples uses a fraction 1/n)
    This is then Sumproducted with the original array.

    Please could you explain how the two COUNTIF(OFFSET()) functions are
    constructed and how they work

    many thanks
    RES

  18. #18
    Harlan Grove
    Guest

    re: minimum along rows:creates an array

    [email protected] wrote...
    ....
    >>=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >>COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >>0,1,COLUMNS(Rng)),Rng&""))

    >
    >So far I think it creates an array the size of the range that identifies
    >(1 or 0) the lowest number (or if n multiples uses a fraction 1/n)
    >This is then Sumproducted with the original array.
    >
    >Please could you explain how the two COUNTIF(OFFSET()) functions are
    >constructed and how they work


    The key is the OFFSET calls. They return what are effectively arrays of
    range references, in this case arrays of references to each row in Rng.
    That's due to the 2nd argument which evaluates to an array of serial
    numbers from 0 to N-1 where N is the number of rows in Rng. COUNTIF,
    SUMIF, N and T seem to be the only functions that can handle such
    arrays. COUNTIF and SUMIF return array results as if their (scalar)
    criteria argument had been applied to each range in the array of range
    references.

    The first COUNTIF call returns an array of nonnegative numbers in which
    zero corresponds to the max value (the value for which there are no
    values strictly larger). The equality test after boolean to numeric
    conversion then has ones for max values and zeros for smaller values.
    The second COUNTIF call in the denominator returns the number of max
    values.

    As for the interaction of OFFSET-generated arrays of ranges and an
    array criteria argument to COUNTIF, it seems to work when the arrays
    conform. The return value is the same size as the criteria argument and
    is equivalent to applying each separate range to the entire criteria
    array.


  19. #19
    Harlan Grove
    Guest

    re: minimum along rows:creates an array

    [email protected] wrote...
    ....
    >>=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >>COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >>0,1,COLUMNS(Rng)),Rng&""))

    >
    >So far I think it creates an array the size of the range that identifies
    >(1 or 0) the lowest number (or if n multiples uses a fraction 1/n)
    >This is then Sumproducted with the original array.
    >
    >Please could you explain how the two COUNTIF(OFFSET()) functions are
    >constructed and how they work


    The key is the OFFSET calls. They return what are effectively arrays of
    range references, in this case arrays of references to each row in Rng.
    That's due to the 2nd argument which evaluates to an array of serial
    numbers from 0 to N-1 where N is the number of rows in Rng. COUNTIF,
    SUMIF, N and T seem to be the only functions that can handle such
    arrays. COUNTIF and SUMIF return array results as if their (scalar)
    criteria argument had been applied to each range in the array of range
    references.

    The first COUNTIF call returns an array of nonnegative numbers in which
    zero corresponds to the max value (the value for which there are no
    values strictly larger). The equality test after boolean to numeric
    conversion then has ones for max values and zeros for smaller values.
    The second COUNTIF call in the denominator returns the number of max
    values.

    As for the interaction of OFFSET-generated arrays of ranges and an
    array criteria argument to COUNTIF, it seems to work when the arrays
    conform. The return value is the same size as the criteria argument and
    is equivalent to applying each separate range to the entire criteria
    array.


  20. #20

    re: minimum along rows:creates an array

    Harlan
    thanks for taking the time to explain this.
    there are a few new elements for me to use. My initial efforts to solve
    the op's question had lead me down OFFSET with an array call. However, as
    you point out, MIN does not work.
    Therefore, I now understand the use of the two COUNTIFs to mimic this
    action.
    I did solve the problem with a brute force UDF but I do like the idea of
    using worksheet functions when I can.


  21. #21

    re: minimum along rows:creates an array

    Harlan
    I have tried to work out how your formula works and am struggling

    >=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >0,1,COLUMNS(Rng)),Rng&""))


    So far I think it creates an array the size of the range that identifies
    (1 or 0) the lowest number (or if n multiples uses a fraction 1/n)
    This is then Sumproducted with the original array.

    Please could you explain how the two COUNTIF(OFFSET()) functions are
    constructed and how they work

    many thanks
    RES

  22. #22
    Harlan Grove
    Guest

    re: minimum along rows:creates an array

    [email protected] wrote...
    ....
    >>=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >>COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >>0,1,COLUMNS(Rng)),Rng&""))

    >
    >So far I think it creates an array the size of the range that identifies
    >(1 or 0) the lowest number (or if n multiples uses a fraction 1/n)
    >This is then Sumproducted with the original array.
    >
    >Please could you explain how the two COUNTIF(OFFSET()) functions are
    >constructed and how they work


    The key is the OFFSET calls. They return what are effectively arrays of
    range references, in this case arrays of references to each row in Rng.
    That's due to the 2nd argument which evaluates to an array of serial
    numbers from 0 to N-1 where N is the number of rows in Rng. COUNTIF,
    SUMIF, N and T seem to be the only functions that can handle such
    arrays. COUNTIF and SUMIF return array results as if their (scalar)
    criteria argument had been applied to each range in the array of range
    references.

    The first COUNTIF call returns an array of nonnegative numbers in which
    zero corresponds to the max value (the value for which there are no
    values strictly larger). The equality test after boolean to numeric
    conversion then has ones for max values and zeros for smaller values.
    The second COUNTIF call in the denominator returns the number of max
    values.

    As for the interaction of OFFSET-generated arrays of ranges and an
    array criteria argument to COUNTIF, it seems to work when the arrays
    conform. The return value is the same size as the criteria argument and
    is equivalent to applying each separate range to the entire criteria
    array.


  23. #23

    re: minimum along rows:creates an array

    Harlan
    thanks for taking the time to explain this.
    there are a few new elements for me to use. My initial efforts to solve
    the op's question had lead me down OFFSET with an array call. However, as
    you point out, MIN does not work.
    Therefore, I now understand the use of the two COUNTIFs to mimic this
    action.
    I did solve the problem with a brute force UDF but I do like the idea of
    using worksheet functions when I can.


  24. #24

    re: minimum along rows:creates an array

    Harlan
    I have tried to work out how your formula works and am struggling

    >=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >0,1,COLUMNS(Rng)),Rng&""))


    So far I think it creates an array the size of the range that identifies
    (1 or 0) the lowest number (or if n multiples uses a fraction 1/n)
    This is then Sumproducted with the original array.

    Please could you explain how the two COUNTIF(OFFSET()) functions are
    constructed and how they work

    many thanks
    RES

  25. #25
    Harlan Grove
    Guest

    re: minimum along rows:creates an array

    [email protected] wrote...
    ....
    >>=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >>COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >>0,1,COLUMNS(Rng)),Rng&""))

    >
    >So far I think it creates an array the size of the range that identifies
    >(1 or 0) the lowest number (or if n multiples uses a fraction 1/n)
    >This is then Sumproducted with the original array.
    >
    >Please could you explain how the two COUNTIF(OFFSET()) functions are
    >constructed and how they work


    The key is the OFFSET calls. They return what are effectively arrays of
    range references, in this case arrays of references to each row in Rng.
    That's due to the 2nd argument which evaluates to an array of serial
    numbers from 0 to N-1 where N is the number of rows in Rng. COUNTIF,
    SUMIF, N and T seem to be the only functions that can handle such
    arrays. COUNTIF and SUMIF return array results as if their (scalar)
    criteria argument had been applied to each range in the array of range
    references.

    The first COUNTIF call returns an array of nonnegative numbers in which
    zero corresponds to the max value (the value for which there are no
    values strictly larger). The equality test after boolean to numeric
    conversion then has ones for max values and zeros for smaller values.
    The second COUNTIF call in the denominator returns the number of max
    values.

    As for the interaction of OFFSET-generated arrays of ranges and an
    array criteria argument to COUNTIF, it seems to work when the arrays
    conform. The return value is the same size as the criteria argument and
    is equivalent to applying each separate range to the entire criteria
    array.


  26. #26

    re: minimum along rows:creates an array

    Harlan
    I have tried to work out how your formula works and am struggling

    >=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >0,1,COLUMNS(Rng)),Rng&""))


    So far I think it creates an array the size of the range that identifies
    (1 or 0) the lowest number (or if n multiples uses a fraction 1/n)
    This is then Sumproducted with the original array.

    Please could you explain how the two COUNTIF(OFFSET()) functions are
    constructed and how they work

    many thanks
    RES

  27. #27

    re: minimum along rows:creates an array

    Harlan
    thanks for taking the time to explain this.
    there are a few new elements for me to use. My initial efforts to solve
    the op's question had lead me down OFFSET with an array call. However, as
    you point out, MIN does not work.
    Therefore, I now understand the use of the two COUNTIFs to mimic this
    action.
    I did solve the problem with a brute force UDF but I do like the idea of
    using worksheet functions when I can.


  28. #28
    Harlan Grove
    Guest

    re: minimum along rows:creates an array

    [email protected] wrote...
    ....
    >>=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >>COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >>0,1,COLUMNS(Rng)),Rng&""))

    >
    >So far I think it creates an array the size of the range that identifies
    >(1 or 0) the lowest number (or if n multiples uses a fraction 1/n)
    >This is then Sumproducted with the original array.
    >
    >Please could you explain how the two COUNTIF(OFFSET()) functions are
    >constructed and how they work


    The key is the OFFSET calls. They return what are effectively arrays of
    range references, in this case arrays of references to each row in Rng.
    That's due to the 2nd argument which evaluates to an array of serial
    numbers from 0 to N-1 where N is the number of rows in Rng. COUNTIF,
    SUMIF, N and T seem to be the only functions that can handle such
    arrays. COUNTIF and SUMIF return array results as if their (scalar)
    criteria argument had been applied to each range in the array of range
    references.

    The first COUNTIF call returns an array of nonnegative numbers in which
    zero corresponds to the max value (the value for which there are no
    values strictly larger). The equality test after boolean to numeric
    conversion then has ones for max values and zeros for smaller values.
    The second COUNTIF call in the denominator returns the number of max
    values.

    As for the interaction of OFFSET-generated arrays of ranges and an
    array criteria argument to COUNTIF, it seems to work when the arrays
    conform. The return value is the same size as the criteria argument and
    is equivalent to applying each separate range to the entire criteria
    array.


  29. #29

    re: minimum along rows:creates an array

    Harlan
    thanks for taking the time to explain this.
    there are a few new elements for me to use. My initial efforts to solve
    the op's question had lead me down OFFSET with an array call. However, as
    you point out, MIN does not work.
    Therefore, I now understand the use of the two COUNTIFs to mimic this
    action.
    I did solve the problem with a brute force UDF but I do like the idea of
    using worksheet functions when I can.


  30. #30

    re: minimum along rows:creates an array

    Harlan
    I have tried to work out how your formula works and am struggling

    >=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >0,1,COLUMNS(Rng)),Rng&""))


    So far I think it creates an array the size of the range that identifies
    (1 or 0) the lowest number (or if n multiples uses a fraction 1/n)
    This is then Sumproducted with the original array.

    Please could you explain how the two COUNTIF(OFFSET()) functions are
    constructed and how they work

    many thanks
    RES

  31. #31
    Bruno Campanini
    Guest

    re: minimum along rows:creates an array

    "Harlan Grove" <[email protected]> wrote in message
    news:[email protected]...
    > Bruno Campanini wrote...
    >>"Harlan Grove" <[email protected]> wrote in message

    > ...
    >>>=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >>>COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >>>0,1,COLUMNS(Rng)),Rng))

    >>
    >>The second formula doesn't work with me; I get #DIV/0!
    >>What's wrong?

    >
    > If you have any blank cells in Rng, you'd need to change the formula to
    >
    > =SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    > COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    > 0,1,COLUMNS(Rng)),Rng&""))


    I didn't have any blank cells in Rng.
    But now the new formula works fine.

    Many thanks
    Bruno



  32. #32
    Harlan Grove
    Guest

    re: minimum along rows:creates an array

    Bruno Campanini wrote...
    >"Harlan Grove" <[email protected]> wrote in message

    ....
    >>=SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    >>COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    >>0,1,COLUMNS(Rng)),Rng))

    >
    >The second formula doesn't work with me; I get #DIV/0!
    >What's wrong?


    If you have any blank cells in Rng, you'd need to change the formula to

    =SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    0,1,COLUMNS(Rng)),Rng&""))


  33. #33
    Bruno Campanini
    Guest

    re: minimum along rows:creates an array

    "Harlan Grove" <[email protected]> wrote in message

    > The simplest way to handle your example data (or any 2-column
    > comparison) would be to use an array formula like
    >
    > =SUM(IF(A1:A3<B1:B3,A1:A3,B1:B3))
    >
    > Getting exotic, if you wanted the sum of the minimum values from each
    > row in the multiple (>2) column range Rng, you could use a formula like
    >
    > =SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    > COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    > 0,1,COLUMNS(Rng)),Rng))


    The second formula doesn't work with me; I get #DIV/0!
    What's wrong?

    Bruno




  34. #34
    Harlan Grove
    Guest

    re: minimum along rows:creates an array

    [email protected] wrote...
    >Is it possible to sum up the minimums of each row in one line commmand?
    >
    >E.g.
    >
    > A B
    >1 5 6
    >2 2 0
    >3 1 3
    >
    >Ans: 5 + 0 + 1

    ....

    The simplest way to handle your example data (or any 2-column
    comparison) would be to use an array formula like

    =SUM(IF(A1:A3<B1:B3,A1:A3,B1:B3))

    Getting exotic, if you wanted the sum of the minimum values from each
    row in the multiple (>2) column range Rng, you could use a formula like

    =SUMPRODUCT(Rng,(COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),0,1,
    COLUMNS(Rng)),"<"&Rng)=0)/COUNTIF(OFFSET(Rng,ROW(Rng)-CELL("Row",Rng),
    0,1,COLUMNS(Rng)),Rng))


  35. #35
    Bruno Campanini
    Guest

    re: minimum along rows:creates an array

    <[email protected]> wrote in message
    news:eU6%[email protected]...
    >I have tried a few formula options with no luck
    > however if a UDF would help
    >
    > Function SumMin(myInfo As Range) As Double
    > Dim RowCount As Integer
    > Dim i As Integer
    > SumMin = 0
    > RowCount = myInfo.Rows.Count
    > For i = 1 To RowCount
    > SumMin = SumMin + WorksheetFunction.Min(myInfo.Rows(i))
    > Next i
    > End Function
    >
    > As with much of my work it feels like brute force but seems to do the job


    Yes, it works fine!
    My bruter force would omit SumMin = 0

    Bye
    Bruno



  36. #36

    re: minimum along rows:creates an array

    I have tried a few formula options with no luck
    however if a UDF would help

    Function SumMin(myInfo As Range) As Double
    Dim RowCount As Integer
    Dim i As Integer
    SumMin = 0
    RowCount = myInfo.Rows.Count
    For i = 1 To RowCount
    SumMin = SumMin + WorksheetFunction.Min(myInfo.Rows(i))
    Next i
    End Function

    As with much of my work it feels like brute force but seems to do the job
    <g>

    if you need a primer on UDFs then
    http://www.mvps.org/dmcritchie/excel/getstarted.htm
    is a good place to start

    hth RES

  37. #37

    re: minimum along rows:creates an array

    Sorry for misleading, the first column indicate the row number.
    Simply, I rewrite it as follows:

    A B
    5 6
    2 0
    1 3
    : :

    Expected result: 5 + 0 + 1 + ...

    Bruno Campanini =E5=AF=AB=E9=81=93=EF=BC=9A

    > <[email protected]> wrote in message
    > news:[email protected]...
    > > Hi,
    > > Is it possible to sum up the minimums of each row in one line commmand?
    > > E.g.
    > > A B
    > > 1 5 6
    > > 2 2 0
    > > 3 1 3
    > > Ans: 5 + 0 + 1
    > > I've tried
    > > {=3Dsum(min(a1:a3,b1:b3))}
    > > but it doesn't work.
    > > Thanks

    >
    > You have 2 numbers in column A and one in B.
    > Why Ans: 5 + 0 + 1?
    > Shouldn't be 1 + 0 + 1?
    >=20
    > Bruno



  38. #38
    Bruno Campanini
    Guest

    re: minimum along rows:creates an array

    <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    > Is it possible to sum up the minimums of each row in one line commmand?
    > E.g.
    > A B
    > 1 5 6
    > 2 2 0
    > 3 1 3
    > Ans: 5 + 0 + 1
    > I've tried
    > {=sum(min(a1:a3,b1:b3))}
    > but it doesn't work.
    > Thanks


    You have 2 numbers in column A and one in B.
    Why Ans: 5 + 0 + 1?
    Shouldn't be 1 + 0 + 1?

    Bruno



  39. #39
    dtb
    Guest

    re: minimum along rows:creates an array

    Try this:
    =SUM(MIN(A1:B1),MIN(A2:B2),MIN(A3:B3))
    --
    Regards,
    db

  40. #40

    minimum along rows

    Hi,

    Is it possible to sum up the minimums of each row in one line commmand?

    E.g.

    A B
    1 5 6
    2 2 0
    3 1 3

    Ans: 5 + 0 + 1

    I've tried

    {=sum(min(a1:a3,b1:b3))}

    but it doesn't work.

    Thanks


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1