Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
THRUST SERVICES & TOOLS
CLOUD EDITIONS
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Crosstab sum the values of irrelevant columns into one column
mmarto
Hi all,<br />
<br />
I have the following problem.. I have a crosstab let say sales by country and product:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>Product1 Product2 Product3 Product4 Product5 Product6 .. ProductN
Country1 260 230 120 10 6 1 0
Country2 180 145 89 4 1 0 0
Country3 125 123 53 1 0 0 0
Country4 70 30 12 2 0 0 0
Country5 10 5 6 3 0 0 0
..
CountryN 1 2 1 0 0 0 0
Sum Country 646 535 281 20 7 1 0</pre>
<br />
I would like to sum the values of all columns that <strong class='bbc'>sum country is =< 20</strong> and put them into a new column called Others: <br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>Product1 Product2 Product3 Others
Country1 260 230 120 17
Country2 180 145 89 5
Country3 125 123 53 1
Country4 70 30 12 2
Country5 10 5 6 3
..
CountryN 1 2 1 0
Sum Country 646 535 281 28</pre>
<br />
I have no clue how to achive that. Any tip would be appreciated.<br />
Thanks
Find more posts tagged with
Comments
Yogesh Maharwade
hi
To achieve this ,better to do it on query side.
mmarto
<blockquote class='ipsBlockquote' data-author="'piwya'" data-cid="83938" data-time="1318330666" data-date="11 October 2011 - 03:57 AM"><p>
hi<br />
To achieve this ,better to do it on query side.<br /></p></blockquote>
<br />
The problem is that on the query level I don't have the sum for all countries. It is done later by the crosstab. So beforehand I don't have a way of knowing which product generated less than 20 sales for all countries
mwilliams
If you aren't able to get your query to give you the correct data, you could always store the values from a grouped table and dataSet or from your crosstab into arrays and then use this data to create a new dataSet that changes the "product" to "other" if the totals you've gathered aren't above 20. Then you could use this scripted dataSet as your cube source.
b_ralu_83
<blockquote class='ipsBlockquote' data-author="'mwilliams'" data-cid="84192" data-time="1318869034" data-date="17 October 2011 - 09:30 AM"><p>
If you aren't able to get your query to give you the correct data, you could always store the values from a grouped table and dataSet or from your crosstab into arrays and then use this data to create a new dataSet that changes the "product" to "other" if the totals you've gathered aren't above 20. Then you could use this scripted dataSet as your cube source.<br /></p></blockquote>
<br />
Hello, <br />
I am into a similar situation, i need to display a subtotal (with some conditions). I can do this directly in my query, but in this case my report will become very slow and will take too much time. So your method sounds good.<br />
Can you detail please how can be possible to store the values from a crosstab into an array? And after that i can create a new data set using this array?<br />
Thank you
Hans_vd
Hi Mmarto,<br />
<br />
If your database supports analytical functions you could write a query like this:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>SELECT country,
CASE
WHEN sum(sales) over (PARTITION BY country, product) < 20 THEN 'Others'
ELSE product
END AS product,
sales
FROM your_table</pre>
<br />
No extra work needed, you'll get the "Others" column automatically in the crosstab results<br />
<br />
Regards<br />
Hans