Add additional values to a view result

I try to accomplish following task:
I have a view with all products that were ordered during certain period of time (based on invoice creation time). (view is of type of order) I am using sql agregation and table display.
I have 3 products: apple, orange, banana

Problem: If orange was not ordered, it is not shown in results like this (and I understand that is because I work with ubercart order which contains only ordered products)

apple 3 banana 2 

What I need, is to show 0 value for products that were not ordered as well:

apple 3 banana 2 orange 0 

How is this possible to solve? Maybe add values to view result? Thank you for help.

EDIT: it is not possible to create the view using relationships other way around (create view type of node and use relationship to order) as suggested by @ J. Reynolds, because I use invoice date for filtering ordered products and it is not possible to get to invoice data (probably because invoice data are in different table)
I also tried combining 2 results together using solution here https://www.drupal.org/node/1013774#comment-4547362 but it seems that it is working only if both views are same of same type. (I just simply can not create a view of type ubercart order product or ubercart order and display products that were not ordered.)

EDIT: After reviewing 2 answers (by @routh and @viktor.likin) I think both are wrong. The problem is that the table I use to get ordered products amounts (uc_order_products) simply does NOT contain products that were not ordered. It contains ONLY orders that were ordered. Logically I am not able to show all products in my table.

Generated queryfollowed by exported view

SELECT uc_orders.order_id AS order_id,    uc_order_products.model AS uc_order_products_model,    uc_orders.uid AS uc_orders_uid,    uc_order_products.title AS uc_order_products_title,    SUM(uc_order_products.qty) AS uc_order_products_qty  FROM uc_orders uc_orders   LEFT JOIN uc_invoice uc_invoice ON uc_orders.order_id = uc_invoice.order_id  LEFT JOIN uc_order_products uc_order_products ON uc_orders.order_id = uc_order_products.order_id  WHERE (uc_invoice.created >= 1396303200) AND (uc_invoice.created <= 1398895199) AND (uc_orders.order_status not in ('canceled', 'canceled1'))  GROUP BY uc_order_products_title   ORDER BY uc_order_products_model ASC 

Exported view:

$view = new view; $view->name = 'testsumuuu'; $view->description = ''; $view->tag = ''; $view->base_table = 'uc_orders'; $view->core = 6; $view->api_version = '2'; $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ $handler = $view->new_display('default', 'Defaults', 'default'); $handler->override_option('fields', array(   'model' => array(     'label' => 'SKU',     'alter' => array(       'alter_text' => 0,       'text' => '',       'make_link' => 0,       'path' => '',       'absolute' => 0,       'link_class' => '',       'alt' => '',       'rel' => '',       'prefix' => '',       'suffix' => '',       'target' => '',       'help' => '',       'trim' => 0,       'max_length' => '',       'word_boundary' => 1,       'ellipsis' => 1,       'html' => 0,       'strip_tags' => 0,     ),     'empty' => '',     'hide_empty' => 0,     'empty_zero' => 0,     'hide_alter_empty' => 1,     'exclude' => 0,     'id' => 'model',     'table' => 'uc_order_products',     'field' => 'model',     'relationship' => 'none',   ),   'order_id' => array(     'label' => 'Order ID',     'alter' => array(       'alter_text' => 0,       'text' => '',       'make_link' => 0,       'path' => '',       'absolute' => 0,       'link_class' => '',       'alt' => '',       'rel' => '',       'prefix' => '',       'suffix' => '',       'target' => '',       'help' => '',       'trim' => 0,       'max_length' => '',       'word_boundary' => 1,       'ellipsis' => 1,       'html' => 0,       'strip_tags' => 0,     ),     'empty' => '',     'hide_empty' => 0,     'empty_zero' => 0,     'hide_alter_empty' => 1,     'link_to_order' => 0,     'exclude' => 1,     'id' => 'order_id',     'table' => 'uc_orders',     'field' => 'order_id',     'relationship' => 'none',   ),   'title' => array(     'label' => 'Title',     'alter' => array(       'alter_text' => 0,       'text' => '',       'make_link' => 0,       'path' => '',       'absolute' => 0,       'link_class' => '',       'alt' => '',       'rel' => '',       'prefix' => '',       'suffix' => '',       'target' => '',       'help' => '',       'trim' => 0,       'max_length' => '',       'word_boundary' => 1,       'ellipsis' => 1,       'html' => 0,       'strip_tags' => 0,     ),     'empty' => '',     'hide_empty' => 0,     'empty_zero' => 0,     'hide_alter_empty' => 1,     'exclude' => 0,     'id' => 'title',     'table' => 'uc_order_products',     'field' => 'title',     'relationship' => 'none',   ),   'qty' => array(     'label' => '',     'alter' => array(       'alter_text' => 0,       'text' => '',       'make_link' => 0,       'path' => '',       'absolute' => 0,       'link_class' => '',       'alt' => '',       'rel' => '',       'prefix' => '',       'suffix' => '',       'target' => '',       'help' => '',       'trim' => 0,       'max_length' => '',       'word_boundary' => 1,       'ellipsis' => 1,       'html' => 0,       'strip_tags' => 0,     ),     'empty' => '',     'hide_empty' => 0,     'empty_zero' => 0,     'hide_alter_empty' => 1,     'exclude' => 0,     'id' => 'qty',     'table' => 'uc_order_products',     'field' => 'qty',     'relationship' => 'none',   ),   'views_sql_groupedfields' => array(     'label' => 'Group By Fields',     'alter' => array(       'alter_text' => FALSE,       'text' => '',       'make_link' => FALSE,       'path' => '',       'absolute' => '',       'alt' => '',       'rel' => '',       'link_class' => '',       'prefix' => '',       'suffix' => '',       'target' => '',       'trim' => FALSE,       'max_length' => '',       'word_boundary' => TRUE,       'ellipsis' => TRUE,       'strip_tags' => FALSE,       'html' => FALSE,     ),     'empty' => '',     'hide_empty' => 0,     'empty_zero' => 0,     'hide_alter_empty' => 1,     'exclude' => '1',     'id' => 'views_sql_groupedfields',     'table' => 'views_groupby',     'field' => 'views_sql_groupedfields',     'relationship' => 'none',     'views_groupby_fields_to_group' => array(       'title' => 'title',     ),     'views_groupby_sql_function' => 'sum',     'views_groupby_fields_to_aggregate' => array(       'qty' => 'qty',     ),     'views_groupby_field_sortby' => 'model',     'views_groupby_sortby_direction' => 'asc',   ), )); $handler->override_option('filters', array(   'created' => array(     'operator' => 'between',     'value' => array(       'type' => 'date',       'value' => '',       'min' => '2014-04-01 00:00:00',       'max' => '2014-04-30 23:59:59',     ),     'group' => '0',     'exposed' => TRUE,     'expose' => array(       'use_operator' => 0,       'operator' => 'created_op',       'identifier' => 'created',       'label' => 'Ubercart invoice number: Invoice date',       'optional' => 1,       'remember' => 0,     ),     'id' => 'created',     'table' => 'uc_invoice',     'field' => 'created',     'relationship' => 'none',     'override' => array(       'button' => 'Override',     ),   ),   'order_status' => array(     'operator' => 'not in',     'value' => array(       'canceled' => 'canceled',       'canceled1' => 'canceled1',     ),     'group' => '0',     'exposed' => FALSE,     'expose' => array(       'operator' => FALSE,       'label' => '',     ),     'id' => 'order_status',     'table' => 'uc_orders',     'field' => 'order_status',     'relationship' => 'none',   ), )); $handler->override_option('access', array(   'type' => 'none', )); $handler->override_option('cache', array(   'type' => 'none', )); $handler->override_option('use_ajax', TRUE); $handler->override_option('items_per_page', 0); $handler->override_option('style_plugin', 'sheet'); $handler->override_option('style_options', array(   'grouping' => '',   'expansion' => '0',   'template' => 0,   'sheetsave' => 'socialcalc:version:1.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary=SocialCalcSpreadsheetControlSave --SocialCalcSpreadsheetControlSave Content-type: text/plain; charset=UTF-8  # SocialCalc Spreadsheet Control Save version:1.0 part:sheet part:edit part:audit --SocialCalcSpreadsheetControlSave Content-type: text/plain; charset=UTF-8  version:1.5 sheet:c:1:r:1 --SocialCalcSpreadsheetControlSave Content-type: text/plain; charset=UTF-8  version:1.0 rowpane:0:1:36 colpane:0:1:8 ecell:A1 sort::-1:up:::: --SocialCalcSpreadsheetControlSave Content-type: text/plain; charset=UTF-8  --SocialCalcSpreadsheetControlSave-- ', )); $handler->override_option('exposed_block', TRUE); $handler = $view->new_display('block', 'Block', 'block_1'); $handler->override_option('block_description', ''); $handler->override_option('block_caching', -1); 

enter image description here

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Add additional values to a view result

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.