Hi, I have problem with a 'Toal Column' while using crosstab with crosstab.col. My Purpose is calculate the total_percent by the SUM(Sale)/SUM(GP), not sum by individual percent, Let me show example:
select 'dbr.sum', 'Sale', 'GP';
select 'dbr.calc', 'percent', '[Sale]/[GP]*100';
select 'dbr.crosstab', 'xMonth'; select 'dbr.hnull', 'total_percent'; select 'dbr.calc', 'total_percent', '[Sale]/[GP]*100';
select 'dbr.hidedatacolumn', 'total_percent';
select concat(Year
, '.M', Month
) as xMonth, SUM(Sale) as 'Sale[Sale]', SUM(GP) as 'GP[GP]', null as 'percent'
from DB group by Year
, Month
where Date_Fixed BETWEEN fromDate and toDate;
This works alright, but the 'total_percent' column is blank, no value is calculated while I add the order crosstab column.
set @iMonth = Month(fromDate);
while( concat(Year(fromDate),right(concat('0',@iMonth),2)) <= concat(Year(toDate),right(concat('0',Month(toDate)),2)) ) do
select 'dbr.crosstab.col', concat('Y',Year(fromDate),'.M',right(concat('0',@iMonth),2));
set @iMonth = @iMonth + 1;
end while;
I have checked this by remove the 2nd block of code, the values of percent total appear.
I am using 4.2.3 build (2434).