need to calculate sum of one column values in adobe campaign classic | Community
Skip to main content
Level 4
February 24, 2025
Solved

need to calculate sum of one column values in adobe campaign classic

  • February 24, 2025
  • 1 reply
  • 629 views

 

 

 

 

Hello all,I am stuck in a requirement where i have to calculate sum of one column in adobe campaign classic ,please suggest how can i get below result as output-specifically last line in display logs after executing query or enrichment activity

 

ClassificationTotal RecipientTotal ContractDiff
61005050
150050450
3800100700
9600200400
4900500400
Total1900900 
Best answer by SushantTrimukheD

Hi @shruti1 ,

You can use the following code after your enrichment activity inside a JavaScript activity. Ensure that all the necessary fields are created and have alias names, so you can reference these alias names in the query. Make sure to adjust the field names in the code to match the actual field names in your schema or enrichment.

// Define the schema name from the target schema var schemaName = vars.targetSchema.substr(vars.targetSchema.indexOf(":") + 1); // Create the query definition to select required fields var query = xtk.queryDef.create( <queryDef schema={vars.targetSchema} operation="select"> <select> <node expr="@totalRecipient"/> <node expr="@totalContract"/> <node expr="@classification"/> </select> </queryDef> ); // Execute the query var result = query.ExecuteQuery(); // Initialize variables to store the sums var totalRecipient = 0; var totalContract = 0; var totalDiff = 0; // Loop through each record in the result set for each (var rcp in result.recipient) { // Sum TotalRecipient and TotalContract totalRecipient += rcp.TotalRecipient; totalContract += rcp.TotalContract; // Calculate the difference and sum it totalDiff += rcp.TotalRecipient - rcp.TotalContract; } // Log the calculated totals logInfo("Total Recipient Sum: " + totalRecipient); logInfo("Total Contract Sum: " + totalContract); logInfo("Total Diff Sum: " + totalDiff);

 Thanks

 

1 reply

SushantTrimukheD
SushantTrimukheDAccepted solution
Level 4
February 25, 2025

Hi @shruti1 ,

You can use the following code after your enrichment activity inside a JavaScript activity. Ensure that all the necessary fields are created and have alias names, so you can reference these alias names in the query. Make sure to adjust the field names in the code to match the actual field names in your schema or enrichment.

// Define the schema name from the target schema var schemaName = vars.targetSchema.substr(vars.targetSchema.indexOf(":") + 1); // Create the query definition to select required fields var query = xtk.queryDef.create( <queryDef schema={vars.targetSchema} operation="select"> <select> <node expr="@totalRecipient"/> <node expr="@totalContract"/> <node expr="@classification"/> </select> </queryDef> ); // Execute the query var result = query.ExecuteQuery(); // Initialize variables to store the sums var totalRecipient = 0; var totalContract = 0; var totalDiff = 0; // Loop through each record in the result set for each (var rcp in result.recipient) { // Sum TotalRecipient and TotalContract totalRecipient += rcp.TotalRecipient; totalContract += rcp.TotalContract; // Calculate the difference and sum it totalDiff += rcp.TotalRecipient - rcp.TotalContract; } // Log the calculated totals logInfo("Total Recipient Sum: " + totalRecipient); logInfo("Total Contract Sum: " + totalContract); logInfo("Total Diff Sum: " + totalDiff);

 Thanks