Skip to Content
avatar image
Former Member

Calculate totals of segments that occur multiple times

Hi , I am looking for help in mapping for the following scenario.

I have a segment (multiple occurances) in the source as shown below:

dicounts

itemno

disocountType

amount

Target segment (one occurance) looks like this:

discountTotals

disocountType

amount

The total of all amounts of a particuler discount type needs to be moved to target amount field.

Example:

dicounts

itemno:1001

disocountType:K

amount:100

discounts

itemno:1002

disocountType:K

amount:200

discounts

itemno:1001

disocountType:P

amount:150

the total of all discounts of type: K has to be moved to target segment

Target segment:

discountTotals

disocountType: K

amount:300

We tried to use functions : SUM and removeContexts, but not able to impose conditions. Its adding all the disocounts(irrespective of discount type=K) and returning 450 (100200150).

Thanks,

Rajesh

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

7 Answers

  • Best Answer
    Nov 26, 2008 at 07:28 AM

    Hi,

    Do like this, actually in your case sum is taking place before the condition check for discount type

    do a little change in mapping

    DiscntType--removeContext--
                                         EqulsS-------IfWithoutElse----Amount---removecontext--then---SUM-
     Connstatnt(Value)
    
    --->GrandAmount

    Thanks!

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 26, 2008 at 07:16 AM

    hi

    you can try like that.

    amount -


    > remove context---->sort by key(disocountType(remove contect))


    >split bue value(for value change)
    (sum)
    ---> amount.

    here sort the maount value by keeping discount type as key...

    regards,

    navneet

    Edited by: navneet sumit on Nov 26, 2008 8:30 AM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 26, 2008 at 07:22 AM

    Hi,

    Use the mapping like below..

    disocountType(same context)-equalsS(TextFunction)IfWithouElseamount(Parent Context)(Then)-->

    disocountType(Parent Context)

    ->RemoveContextSum(Statistic Function)-Target(amount).

    Regards,

    Prakasu

    Edited by: prakasu on Nov 26, 2008 8:23 AM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 26, 2008 at 07:33 AM

    Use the remove context for both DicountType and Amount while checking the condition.

    Add comment
    10|10000 characters needed characters exceeded

  • Nov 26, 2008 at 08:23 AM

    Hi,

    Please use the mapping below:

    for the discountTotals node:

    discountType --> removeContext --> sort: Lexicographical(case insensitive) --> splitByValue:ValueChanged --> collapseContext --> discountTotals

    this creates the discountTotals node based on the number of the discountType unique occurrences

    for the discountType node:

    discountType --> removeContext --> sort: Lexicographical(case insensitive) --> splitByValue:ValueChanged --> collapseContext --> splitByValue:eachValue --> discountType

    same as above, e.g. if only P and K are declared, then the mapping will only output a P and a K once

    for the amount node:

    discountType --> removeContext --> sortByKey:(LexicographicalCaseInsensitive) 1.

    amount --> removeContext -->

    discountType ->removeContext ->sort:Lexicographical(CaseInsensitive) ->splitByValue:ValChngd 2.

    node from 1. --> formatByExample --> sum --> amount

    node from 2. -->

    before you can do a total for each type (P or K), you have to use formatByExample to separate which values belong to P or K. The mapping also took into account that the occurrence order could be P,K,P,K...so that using formatByExample with sort will result to P,P,K,K.

    Regards,

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 26, 2008 at 08:31 AM

    Hi all, thanks a lot for the response. I followed the logic provided by sudhir and able to get the required output.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Nov 26, 2008 at 08:40 AM
    disocountType \
                        ------------equalS----\
    Constant[K]   /                          ----------ifWitoutElse---- removeContext-------sum(from statistics group)----target
                                     amount--/

    ifWitoutElse 2 inputs :-

    1. check whether discount type equals K

    2.amount

    Don't change content of any of the input. removeContext will carry all amounts whose discountType is K, sum will add up all amounts.

    Add comment
    10|10000 characters needed characters exceeded