Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Need a specific, CrossTab-like report
BirtWidi
<p>I need a specific report which looks similar to a cross tab report - but it isn´t a cross tab.</p><p>I need a group of rows for each customer and a group of columns for each month - that´s like each other cross tab.</p><p>The summary field does not contain a aggregation of the matching values. Instead of them it contains a list of all matching values. (Example: see attachment)</p><p> </p><p>How can I create such a report?</p><p> </p><p>Regards,</p><p>Widi</p>
Find more posts tagged with
Comments
micajblock
<p>The easiest way I can think of is to have a table for the customers with 12 columns. In each cell you have another table (or list with bindings so that it filters based on the customer and month.</p>
kclark
<p>I'm not a sql expert but this might help too.</p><pre class="_prettyXprint _lang-">select if(month(payment_date) = 1, amount, null) as Jan, if(month(payment_date) = 2, amount, null) as Feb, if(month(payment_date) = 3, amount, null) as Mar, if(month(payment_date) = 4, amount, null) as Apr, if(month(payment_date) = 5, amount, null) as May, if(month(payment_date) = 6, amount, null) as Jun, if(month(payment_date) = 7, amount, null) as July, if(month(payment_date) = 8, amount, null) as Aug, if(month(payment_date) = 9, amount, null) as Sept, if(month(payment_date) = 10, amount, null) as Oct, if(month(payment_date) = 11, amount, null) as Nov, if(month(payment_date) = 12, amount, null) as Decm, customer_idfrom paymentgroup by payment_date</pre><p>The only problem with that is the empty rows it creates. But if you can get rid of those empty rows and group the cable on the customer number you should have the output your looking for.</p>
GLO_FR
<p>kclark's answer is good but the sql syntax is not the right one.</p><p>Try this</p><p> </p><p>select<br />
customer_id,<br />
myRow,<br />
sum(<strong>case when</strong> payMonth = 1 then amount <strong>end</strong>) as Jan,<br />
sum(case when payMonth = 2 then amount end) as Feb,<br />
sum(case when payMonth = 3 then amount end) as Mar,<br />
sum(case when payMonth = 4 then amount end) as Apr,<br />
sum(case when payMonth = 5 then amount end) as May,<br />
sum(case when payMonth = 6 then amount end) as Jun,<br />
sum(case when payMonth = 7 then amount end) as July,<br />
sum(case when payMonth = 8 then amount end) as Aug,<br />
sum(case when payMonth = 9 then amount end) as Sept,<br />
sum(case when payMonth = 10 then amount end) as Oct,<br />
sum(case when payMonth = 11 then amount end) as Nov,<br />
sum(case when payMonth = 12 then amount end) as Dec<br />
<br />
FROM (Select customer_id,<br />
month(payment_date) as payMonth,<br />
ROW_NUMBER() OVER (ORDER BY customer_id, month(payment_date)) AS myRow, <br />
amount<br />
from payment) AS A<br />
<br />
GROUP BY customer_id, myRow</p><p> </p><p>**</p><p>So with your data</p><p>[font="'courier new', courier, monospace;"]Cust01,02/01/13,Value1<br />
Cust01,02/01/13,Value2<br />
Cust01,10/01/13,Value12<br />
Cust02,03/01/13,Value3<br />
Cust02,05/01/13,Value4<br />
Cust02,05/01/13,Value5<br />
Cust03,07/01/13,Value6<br />
Cust04,03/01/13,Value11<br />
Cust04,09/01/13,Value8<br />
Cust04,09/01/13,Value9<br />
Cust04,09/01/13,Value10[/font]</p><p> </p><p>Sub query 1 <strong>should </strong>give you</p><p>[font="'courier new', courier, monospace;"]Cust_id | Month | Num of value by custid and month | amount[/font]</p><p>[font="'courier new', courier, monospace;"]
+
+
+
<br />
Cust01 | 2 | 1 | Value1<br />
Cust01 | 2 | 2 | Value2<br />
Cust01 | 10 | 1 | Value12<br />
Cust02 | 3 | 1 | Value3<br />
Cust02 | 5 | 1 | Value4<br />
Cust02 | 5 | 2 | Value5<br />
Cust03 | 7 | 1 | Value6<br />
Cust04 | 3 | 1 | Value11<br />
Cust04 | 9 | 1 | Value8<br />
Cust04 | 9 | 2 | Value9<br />
Cust04 | 9 | 3 | Value10[/font]</p><p> </p><p>Than the principal query should give you this</p><p><span style="font-size:8px;">[font="'courier new', courier, monospace;"]Cust_id | Num of value by custid and month | Jan | Feb | Mar | Apr | May | Jun | Jul | Sep | Oct | Nov | Dec[/font]</span></p><p><span style="font-size:8px;">[font="'courier new', courier, monospace;"]
+
+
+
+
+
+
+
+
+
+
+
+<br />
Cust01 | 1 | | Value1 | | | | | | | Value12 | |<br />
Cust01 | 2 | | Value2 | | | | | | | | |<br />
Cust02 | 1 | | Value3 | | | Value4 | | | | | |<br />
Cust02 | 2 | | | | | Value5 | | | | | |<br />
Cust03 | 1 | | | | | | | Value6 | | | |<br />
Cust04 | 1 | | Value11 | | | | | | Value8 | | |<br />
Cust04 | 2 | | | | | | | | Value9 | | |<br />
Cust04 | 3 | | | | | | | | Value10 | | |[/font]</span></p>