In this tutorial, we will learn about the SAQL Functions, what are the different functions that we can use with SAQL to manipulate the data and represent in chart/dashboard.
We will learn about below 2 types of SAQL functions: –
For Example:
a1 = group a by Priority;
a2 = foreach a1 generate Priority as Priority, average(AnnualRevenue) as Revenue;
For Example:
q = foreach q generate ‘Tier’ as ‘Tier’, count() as ‘count’;
For Example:
a1 = group a by Priority;
a2 = foreach a1 generate Priority as Priority, first(AnnualRevenue) as Revenue;
For Example:
a1 = group a by Priority;
a2 = foreach a1 generate Priority as Priority, last(AnnualRevenue) as Revenue;
For Example:
a1 = group a by Priority;
a2 = foreach a1 generate Priority as Priority, max(AnnualRevenue) as maxRevenue;
For Example:
a1 = group a by Priority;
a2 = foreach a1 generate Priority as Priority, min(AnnualRevenue) as maxRevenue;
For Example:
a1 = group a by Priority;
a2 = foreach a1 generate Priority as Priority, median(AnnualRevenue) as Revenue;
For Example:
a1 = group a by Priority;
a2 = foreach a1 generate Priority as Priority, sum(AnnualRevenue) as Revenue;
Date Function: – SAQL date functions use to convert the dimensions and measures to dates. The dates can be used to sort, filter, and group data in your SAQL queries.
For Example:
q = filter q by date(‘CloseDate_Year’, ‘CloseDate_Month’, ‘CloseDate_Day’) in [“current day – 30 days”..];
For Example:
q = foreach q generate date_diff(“year”, toDate(DateOfBirth, “yyyy-MM-dd”), now()) as age;
For Example:
date_to_epoch(toDate(“2018-07-26 15:41:58”)) == 1532599918
For Example:
q = foreach q generate date_to_string(now( ), \”yyyy-MM-dd HH:mm:ss\”) as datestring;
For Example:
q = dateRange([1970, 1, 1], [1970, 1, 31]);
For Example: q = foreach q generate day_in_month( toDate(OrderDate));
For Example: q = foreach q generate day_in_quarter( toDate(OrderDate));
For Example: q = foreach q generate day_in_week( toDate(OrderDate));
For Example: q = foreach q generate day_in_week( toDate(Closedate));
For Example:
q = foreach q generate daysBetween( toDate( OrderDate, “yyyy-MM-dd” ),
toDate( ShipDate, “yyyy-MM-dd” )) as daysToShip;
For Example: toDate(“1532599918”) == toDate(“2018-07-26 15:41:58”)
q = foreach q generate toString(now( ), \”yyyy-MM-dd HH:mm:ss\”) as ds;
In the next blog, we will learn the remaining SAQL functions. Thanks for reading.
Sharing is caring 🙂 😉
Hi,
Could you please throw a simple example stating account records based on user selection dates. For example: Week1 = 01-01-2019 – 08-01-2019
Week2 = 08-01-2019 – 15-01-2019
I need to set these drop downs on the fly in my lens based on user selection on above picklist like week1 or week 2?
I tried many option and get confused and getting varioud error which unable to track
Hi Sunny,
You can have 2 Date picker but at once you can only select the dates in one picker and lenses will get updated accordingly and then you can update the second date picker.
Nice blog. helpful…