[SalesForce] How to bucket field values in Einstein analytics

I have a dataset with a field as Order Country. It has field values as 'AUS', 'USA', 'GBR', 'IND', 'KEN', etc.
Now, is there any way to bucket these values as

bucket 1: 'AUS', 'USA', 'GBR' - Total id count of these three countries
bucket 2: 'USA', 'GBR', 'IND', 'KEN' - Total id count of these Four countries
bucket 3: 'KEN', 'AUS', 'IND' - Total id count of these three countries

Please suggest

Best Answer

Basically you have 2 options:

  1. Bucket in a dataflow or recipe
  2. Bucket in the dashboard. For that you have to write custom SAQL. In your query insert a line containing "case when" like the following
q = foreach q generate case when orderCountry in ["AUS", "USA", "GBR"]
                            then "Yes"
                            else "No"
                       end as Bucket1,
                       case when orderCountry in ["USA", "GBR", "IND", "KEN"]
                            then "Yes"
                            else "No"
                       end as Bucket2,
                       case when orderCountry in ["KEN", "AUS", "IND"]
                            then "Yes"
                            else "No"
                       end as Bucket3;

Then create subqueries to count

result1 = group q by Bucket1;
result1 = foreach result1 generate Bucket1, count() as countBucket1;

result2 = group q by Bucket2;
result2 = foreach result2 generate Bucket2, count() as countBucket2;

result3 = group q by Bucket3;
result3 = foreach result3 generate Bucket3, count() as countBucket3;

And finally union or cogroup the suqueries back together, depending on what you want to do with these numbers.

Hope that helps!

Related Topic