Batch API passing data to finished function I am creating a batch import and I would like to pass two different counts to my finished function. For example in my 'operations' function I check for an NID if it exists update the node if it doesn't then create it.

In my 'finished' function I want to do something like:

 batch_import_finished($success, $results, $operations) {
   if ($success) {
     $message ='Nodes created: '.$nodesCreated. '&lt;br /&gt;';
     $message .='Nodes updated: '.$nodesUpdated;
   }
   else {
     $message = 'some errors';
   }

  drupal_set_message($message);
}


Hope this makes sense.
First, make sure you set the finished process in your batch process. 

$batch = array(
      'title' =&gt; t('Merging content ...'),
      'operations' =&gt; array(
         array('batch_import_import', array($col1, $col2),  //Note we pass 2 variables here.
       ),
      'finished' =&gt; 'batch_import_finished', // set this!
      'init_message' =&gt; t('Connectng to the base site ...'),
      'progress_message' =&gt; t('Processed @current out of @total.'),
      'error_message' =&gt; t('An error occurred during processing'),
      'progressive' =&gt; FALSE
    );
...
batch_set('admin/content');


Then, in your worker function, you can take the last argument passed to it as $context. 

For an example, from above example above, your worker function should be something like this:

function batch_import_import($col1, $col2, &amp;$context) {
  //do the stuff.
  if (!isset($context['results']['created'], $context['results']['updated'])) {
    $context['results']['created'] = 0;
    $context['results']['updated'] = 0;
  }
  $context['results']['created']++; // is_new == TRUE or some logic.
  $context['results']['updated']++; // add some logic to determine created or updated.
}


and then in the finish function, you get $context['results'] as the second argument. 

batch_import_finished($success, $results, $operations) {
   if ($success) {
     $message = t('Nodes created: @count', array('@count' =&gt; $results['created'])).'&lt;br /&gt;';
     $message .= t('Nodes updated: @count', array('@count' =&gt; $results['updated']));
   }
   else {
     $message = t('some errors');
   }

  drupal_set_message($message);
}


I have also corrected the $message as you can use t() function here. 
Note that you pass $context by reference. 
See batch_api examples for more information. This is just some code copied from a module I was developing the other day. 

In the finished function, $operations contain unprocessed items.