LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Sumproduct

    Employee
    Posted 07-20-2010 17:09

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Iain Sanders

    Hi Guys,

    I'm sorry if this is a stupid question, but I need a numerical operator for SUMPRODUCT. I can't find it in the help file.

    Is there one? If not, what is the easiest work-around?

    Many thanks,

    Iain


  • 2.  RE: Sumproduct

    Employee
    Posted 07-21-2010 07:01

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: timonk

    Iain,

    I am assuming you are referring to the Excel SUMPRODUCT function?

    Have you considered the list functions "map" and "reduce"?

    Take a look at this example code. You can drop this into a filter.

    product = map(&*, list(1,2), list(100,200)) #multiply the list elements, return list of results
    sumproduct = reduce(&+, product) #sum the ilist of results
    emit str(sumproduct) as SP, str(product) as P

    You will get
    SP:string P:string
    500 {100;400}

    And of course you can nest these functions:

    reduce(&+, map(&*, list(1,2), list(100,200)))

    Perhaps these can help? You can use the Aggregate node to create lists out of input columns.

    Here's just a quick example. Say you have input columns "A" and "B". We can create lists of them like this:

    ==========================
    if firstInGroup then my_list = list(A)
    else my_list = append(my_list, A)

    if firstInGroup then my_list = list(B)
    else my_list = append(my_list2, B)

    emit str(my_list) as newlist_A, str(my_list2) as newlist_B

    where lastInGroup.
    ###GroupBy value
    true
    ============================

    Then you could just apply the map/reduce from above.


    Just a suggestion. Does this help?

    Regards
    Timon Koufopoulos
    MDA Support.