0

I would like to create stacked bar based on something a saql query like this:

q = load "datasetname";
q = filter q by 'field1' == "false" and 'field2'=="homescreen";
q = filter q by date('eventon_Year', 'eventon_Month', 'eventon_Day') in ["7 days ago".."current day"];
q = group q by all;
q = foreach q generate 
(sum('count_eventcount_0to1000') +
sum('count_eventcount_1000to2000') + 
sum('count_eventcount_2000to3000'))
as '0 to 3 seconds',
(sum('count_eventcount_3000to4000') +
sum('count_eventcount_4000to5000'))
as '3 to 5 seconds',
(sum('count_eventcount_5000to6000') +
sum('count_eventcount_6000to7000') + 
sum('count_eventcount_7000to8000'))
as '5 to 8 seconds',
(sum('count_eventcount_8000to9000') +
sum('count_eventcount_9000to10000'))
as '8 to 10 seconds'
q = foreach q generate '0 to 3 seconds', '3 to 5 seconds', '5 to 8 seconds', '8 to 10 seconds';
q = limit q 2000;

but this gives me only a row of data and I cannot make the measures I created into "bar segments". Is there a way in which I can create different bar segments based on calculations like this above so that the stacked bar works correctly (segments are of proportional length) to values?

  • 1
    Welcome to SFSE! Please try to format your question so that it's easier to read (use code formatting) and you also can just post a relevant sample of code rather than a big code-dump – Brian Miller Jul 21 at 9:03
0

I was able to fix this by querying this way.

    q = load "datasetname";
q = filter q by 'field1' == "false" and 'field2'=="homescreen";
q = filter q by date('eventon_Year', 'eventon_Month', 'eventon_Day') in ["7 days ago".."current day"];
q = group q by all;
q = foreach q generate 
q1 = foreach q generate "0 to 3s" as '# of events',
(sum('count_mobileEPT_0to1000') +
sum('count_mobileEPT_1000to2000') + 
sum('count_mobileEPT_2000to3000'))
as 'count';
q2 = foreach q generate "3s to 5s" as '# of events',
(sum('count_mobileEPT_3000to4000') +
sum('count_mobileEPT_4000to5000'))
as 'count';
q3 = foreach q generate "5s to 8s" as '# of events',
(sum('count_mobileEPT_5000to6000') +
sum('count_mobileEPT_6000to7000') + 
sum('count_mobileEPT_7000to8000'))
as 'count';
q4 = foreach q generate "8s to 10s" as '# of events',
(sum('count_mobileEPT_8000to9000') +
sum('count_mobileEPT_9000to10000'))
as 'count';
q5 = foreach q generate "10s +" as '# of events',
(sum('count_mobileEPT_10000to11000') +
sum('count_mobileEPT_11000to12000') +
sum('count_mobileEPT_12000to13000') +
sum('count_mobileEPT_13000to14000') +
sum('count_mobileEPT_14000to15000') +
sum('count_mobileEPT_15000to16000') +
sum('count_mobileEPT_16000to17000') +
sum('count_mobileEPT_17000to18000') +
sum('count_mobileEPT_18000to19000') +
sum('count_mobileEPT_19000to20000') + 
sum('count_mobileEPT_20000to'))
as 'count';
r = union q1,q2,q3,q4,q5;
q = foreach r generate '# of events', 'count';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.