Need an account? Click to Register
Home arrow Kognitio examples arrow Summary metrics for this week
Summary metrics for this week

kognitio_e5j_thumb.pngThis example drills into the details for the current week. This is a complementary set of reports to the Weekly Metrics Report. In this example, we will focus on the most recent week and explore the top 10 product groups by sales, sales percentage growth, and sales net change. We'll see how the top 10 in each metric performs relative to the other metrics.

Query the database

We start with a single SQL query to the Kognitio WX2 server which is both very fast and can read billions of records in seconds.

The entire nextanalytics script is included at the bottom of this page

Script lines 2 through 5 set up the SQL query. Note that we embedded it in the script for the purposes of making this web page self-contained.  In a production environment, a separate .SQL file would be recommended because it keeps the business logic distinct from the database logic.

The results of the query create the first nextanalytics 'page'. The page has product groups, sales week number, and a total sales column. 

kognitio_e5a.png

Pivot the date dimension to the columns

With one single line of script (script line 9), the text column 'saleweek' is swapped to the column dimension. This is a pivot operation that creates a crosstab. Every unique value of 'saleweek' becomes a column in a new second page. Notice that there was no requirement to predefine the column values, no complicated SQL syntax, no call to a hidden procedure. Also note that there was no reference to any specific value of week, making the report immediately useful for subsequent weeks and ideal for adhoc reporting.

Since our report is only about the most recent week, we select and keep only those two columns (lines 9 and 10 in the script). While we could have changed the SQL query to perform this filtering, we simply reused the query from the previous example. This helps to reduce the portfolio of queries being maintained in the environment and greatly reduces the overhead of the solution in production. It also demonstrates how nextanalytics makes an ideal adhoc analysis tool, using the data you have available.

kognitio_e5b.png

Prepare product group sales column

The first column we want in the final report is the product group sales for the most recent week, so we sort it descending and change the column caption accordingly.

kognitio_e5c.png

Calculate growth

With line 17, we calculate the percentage growth.  Then we rename the columns.

kognitio_e5d.png

Calculate the net change

With line 21, we switch back to the previous page, and then calculate the net change and rename the columns.  

kognitio_e5e.png

Assemble the final report

We now have all the data we want but it is spread over three pages. Script lines 26 through 33 move the columns together in the desired order on a new page. nextanalytics automatically aligns the rows, so even if the three pages contain different product groups in different orders, the resulting page will be correctly combined.

Now that we have the three columns of interest on the same page, we're ready to perform various sorting and alerting for the final three reports.

kognitio_e5h.png

Rank each of the columns 

In each of our final reports, we will sort one of the columns and then rank the values in each column, assigning the number '1' for the largest value, '2' for the next largest and so on. This rank page forms the basis for our alerting (highlighting) operation. 

kognitio_e5i.png

Prepare the first report page

In the first report (script lines 36 through 44), we sorted the Sales column, descending, and the alerting highlights the top 10 rankings for each column.

You can see in the report below that, of the top 10 by sales, only the 'Medical' product group placed in the top 10 of the Growth or Net Change rankings.

kognitio_e5j.png

Continue with the second report

In the next report (script lines 46 through 58), we sorted the Growth column, descending, and the alerting again highlights the top 10 rankings for each column.

You can see in the report image below that, of the top 10 by growth, there are a lot more similarities with the Net Change rankings than with Sales.

kognitio_e5k.png

Keep going with another report from the same data

In the third report (script lines 60 through 74), we sorted the Net Change column, descending, and the alerting highlights the top 10 rankings for each column. 

Three reports from the same data, three different perspectives. One database query. 

kognitio_e5l.png

Summary and complete script listing

As you can see, it is easy to use nextanalytics to generate multiple reports from a single query, allowing the power and speed of the Kognitio WX2 database to be leveraged while easily delivering multiple analyses without having to learn more advanced SQL syntax, or even generating a unique query 9since we reused the query from another example).

As you can see in the listing below, the nextanalytics script langauge is very simple and easy to read. This was, after all, a simple analytical example.

Complete script listing
  1. prompt,add,[CONNECTION],"Driver={White Cross 9000 (32)}; Server=wx2; UID=username; PWD=secret;"
  2. query,command,"select c.group_name as rowlabel_group_name, a.saleweek as text_saleweek, sum(a.price) as numeric_value"
  3. query,commandappend," from v_ret_sale a, v_ret_product b, v_ret_prod_group c"
  4. query,commandappend," where a.prodno = b.prodno and b.group_no = c.group_no"
  5. query,commandappend," group by 1,2"
  6. query,runsave,ODBC,[CONNECTION],05a.NOD
  7. ;--------------
  8. swaptextcolumnwithcolumn,saleweek
  9. selectrange,column,last,2
  10. keepselected
  11. NewRowLabel,Product Group
  12. ;--------------
  13. sort,last,true
  14. changelabelcaption,False,Column,*,Sales
  15. PageCaption,final
  16. ;--------------
  17. RepeatingCalculation,Growth
  18. changelabelcaption,False,Column,*,Growth
  19. PageCaption,finalgrowth
  20. ;--------------
  21. Select,Page,final
  22. RepeatingCalculation,Diff
  23. changelabelcaption,False,Column,*,Net Change
  24. PageCaption,finaldiff
  25. ;--------------
  26. select,column,Last
  27. MoveColumns,Copy,finalgrowth,0,Last
  28. ;--------------
  29. selectrange,column,Last,2
  30. MoveColumns,Copy,final,0,Last
  31. ;--------------
  32. selectrange,column,Last,3
  33. KeepSelected
  34. PageCaption,finaltrio
  35. ;--------------
  36. ChangeValuesToRank,False,Column
  37. PageCaption,ranktrio
  38. ;--------------
  39. Select,Page,finaltrio
  40. selectrange,row,0,20
  41. keepselected
  42. ChangeAlertTo,cellvalue,ranktrio,temp,-1
  43. PageCaption,Top Product Groups by Sales
  44. PageDescription,"This example shows how three columns of different metrics can be copied to a common page for reporting. The alerting shows the top 10 values in each column, with the highest being red and the 10th a deep blue color. It does this by alerting on a hidden page that contains rankings down each of the columns."
  45. ;--------------
  46. Select,page,finaltrio
  47. sort,Growth,True
  48. pagecaption,finaltrio2
  49. ;--------------
  50. ChangeValuesToRank,False,Column
  51. PageCaption,ranktrio2
  52. ;--------------
  53. Select,Page,finaltrio2
  54. selectrange,row,0,20
  55. keepselected
  56. ChangeAlertTo,cellvalue,ranktrio2,temp,-1
  57. PageCaption,Top Product Groups by Growth
  58. PageDescription,"This example sequence shows how sorting on a different column can provide a very different perspective on the data, and how alerting can be used to make important relationships stand out."
  59. ;--------------
  60. Select,page,finaltrio
  61. clearselection,true,true
  62. sort,Net Change,True
  63. pagecaption,finaltrio3
  64. ;--------------
  65. ChangeValuesToRank,False,Column
  66. PageCaption,ranktrio3
  67. ;--------------
  68. Select,Page,finaltrio3
  69. selectrange,row,0,20
  70. keepselected
  71. ChangeAlertTo,cellvalue,ranktrio3,temp,-1
  72. assigncellformat,True,N2,1,Growth,
  73. PageCaption,Top Product Groups by Net Change
  74. PageDescription,"While each example here emphasizes different aspects and relationships, the alerts help the reader to very quickly grasp what is important. For example, in this table, it is apparent that the 'Medical' product group is the top overall performer, being the only product group in the top 10 for sales, growth and net change."

 

 

 
< Prev

kognitio.png

The Kognitio WX2 database can perform complex queries against a very large dataset and return the results very quickly. When coupled with nextanalytics, the query result can be further processed and viewed in a wide variety of customizable and useful ways.

These examples demonstrate how nextanalytics can leverage the power of the Kognitio WX2 database to deliver a complete high speed analytical solution. These examples are provided as an introduction to some of the things that can be done, even when working from a very large dataset (e.g. 11 billion records).  Everything you see is extensible and customizable.

Visit Kognitio's web site for more information.