cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate totals of segments that occur multiple times

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

SudhirT
Active Contributor
0 Kudos

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!

Answers (6)

Answers (6)

Former Member
0 Kudos
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.

Former Member
0 Kudos

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

markangelo_dihiansan
Active Contributor
0 Kudos

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,

Former Member
0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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