Skip to main content

#Saql0 discutindo

I have a dataset containing Opportunity Start Date, Opportunity End Date and Volume columns.

Client has asked to show a visualisation in the Dashboard where volume is distributed between Opportunity Start Date and Opportunity End Date month by month on equally basis throughtout the whole year.

 

For example, for below datapoints.

 

S No || Opportunity Start Date || Opportunity End Date || Volume

1 || 01-01-2023 || 31-12-2023 || 1200

2 || 01-06-2023 || 31-12-2023 || 2400

 

There will be 12 bars in the visualisation showing [ 1200 * 5/12 ] = 500 each for Jan to May

& [ 1200 * 7/12 ] + [ 2400 * 7/12 ] = 2100 each from June to Dec month.

 

Is there a way this can be achieved using SAQL?

 

Alternatively I would have to make the column to row transformation in Recipe by splitting each Opportunity row into 12 rows each for each month and divding the volume eqully.  

 

#CRMAnalytics #Recipe #DataTransformation #SAQL 

2 respostas
  1. 22 de nov. de 2023, 04:19

    I managed to do this in recipe. For simplicity sake I created 12 rows for each record irrespective of the start date and end date and created a new column 'Sub Volume' which is set to "0" or "Volume / No of months between start date and enddate" depending on the start date and end date.

0/9000

Hi,

 

I've run into a roadblock with cogrouping. I have two separate streams in my SAQL I am trying to piece back together:

 

q = load "MyDataset";

r = filter q by 'SomeField' == "True";

r = foreach r generate 'FieldA' as 'FieldA', 'FieldB' as 'FieldB';

s = filter q by 'SomeOtherField' == "True";

s = foreach s generate 'FieldA' as 'FieldA', 'FieldC' as 'FieldC';

t = cogroup r by 'FieldA' left, s by 'FieldA';

t = foreach t generate r.'FieldA' as 'FieldA', r."FieldB' as 'FieldB', s.'FieldC' as 'FieldC';

 

I get 'FieldA' working as expected, but the inclusion of 'FieldB' and 'FieldC' causes an error (it says make sure the field 'FieldB/C' exists and is spelled correctly as if it is not there). Using an aggregation function, however, works - but I do not want to aggregate values. How do I correctly join these two streams and keep the granular level of data in the other fields?

2 comentários
  1. 6 de fev. de 2021, 11:26
    Hello @Dvin Badalzadeh

    You may see if the approach below meets your needs:

    q = load "MyDataset";

    r = filter q by 'SomeField' == "True";

    r = foreach r generate 'FieldA' as 'FieldA', 'FieldB' as 'FieldB';

    r = group r by ('FieldA', 'FieldB');

    s = filter q by 'SomeOtherField' == "True";

    s = foreach s generate 'FieldA' as 'FieldA', 'FieldC' as 'FieldC';

    s = group s by ('FieldA', 'FieldC');

    t = cogroup r by 'FieldA' left, s by 'FieldA';

    t = foreach t generate r.'FieldA' as 'FieldA', r."FieldB' as 'FieldB', s.'FieldC' as 'FieldC';

    Attribution: The answer at

    https://salesforce.stackexchange.com/questions/298871/monday-morning-challenge-join-two-data-streams-with-saql-in-salesforce-einstein
0/9000

Hi All, 

 

Just trying to do a basic case statement in SAQL but with close dates. My goal is to do:

 

"Case when Closedate is between 2020. 04. 01 and 2020, 06, 30 then "Q1"....." etc...

 

I can't quite seem to get the syntax down, will anyone be able to help with this? Cheers!

3 comentários
0/9000

Hi all,

I'm reviewing a dataflow with many conscutive filters node.

The first filter is (dim:N:ABC)

the second one is (dim:N:DEF)

the third is (dim:N:GHI)

ecc

There are 7 consecutive filters nodes.

 

Is possible to merge all these nodes?

is possible to insert in a filter node a filter logic (example: Filter A & filter B &filter B)?

 

tks

2 comentários
  1. 18 de nov. de 2020, 15:31
    The old syntax is confusing, using SAQL as @Roman Michalik noted is much easier and allows for more complex filter. Example: (('Field_A' == "ABC" && 'Field_B' == "XYZ") || 'Field_C' > 0) && 'Field_D' != "false"
0/9000

Hi all, 

 

Have a use case that I need help with.

I have two datasets,

1. Contacts with Reservations

2. Contacts with Email results

 

The only field linking these 2 datasets is the contact Id.

I want to be able to select the Email name ( from second dataset ) in form of a global filter that would give me unique contacts for that 'email name' as a result.

 

Now for those contacts I need to find sum of total Reservations (which is doable), but grouped by Property Codes. (The first dataset has property info as well on reservations)

 

Eg. I select Email name as 'Invitation email' and I get 1000 contacts as a result.

For those 1000 contacts I need sum of reservations, grouped by Property Code.

 

Things that I have tried,

1. using cogroup in SAQL and grouping by contact Id , inner join. I get the sum of reservations but cant find a way to group the results by Property Code (as results are already grouped by Contact Id).

2. Using binding to send result of contact Ids from dataset 2 in a lens of dataset 1 . That is filter dataset 1 by contact Id in [result from binding]. Since there are hundreds of thousands contacts, I get a filter depth exceeded error.

3. Connect data sources doesn't seem to help out here as well.

 

Any kind of help here would be much appreciated.

4 comentários
  1. 26 de out. de 2020, 20:35

    got the solution to my use case by using the below query,

    thanks to

    @Roman Michalik

    for providing the solution,

    In my use case I have have cases and opportunities, both related to Accounts. Now I want to filter the list of accounts by case origin (or any other field in cases) and apply the remaining list of accounts as a filter for opportunities and display only those accounts filtered by cases which have an opportunity.

    This query is working for me:

    q1 = load "case";

    q1 = group q1 by '

    Account.Name

    ';

    q1 = foreach q1 generate '

    Account.Name' as 'Account.Name

    ', unique('Id') as 'unique_Id', 1 as 'relevant', "AAA" as 'StageName';

    q2 = load "opportunity";

    q2 = group q2 by ('

    Account.Name

    ', 'StageName');

    q2 = foreach q2 generate '

    Account.Name' as 'Account.Name

    ', 'StageName' as 'StageName', sum('Amount') as 'sum_Amount';

    q = cogroup q1 by ('

    Account.Name','StageName') full,q2 by ('Account.Name

    ','StageName');

    q = foreach q generate coalesce(q1.'

    Account.Name',q2.'Account.Name') as 'Account.Name

    ', coalesce(q1.'StageName',q2.'StageName') as 'StageName', coalesce(sum(q2.'sum_Amount'),0) as 'sum_Amount', coalesce(avg(q1.'relevant'),0) as 'relevant';

    --distribute "relevant" to all rows per Account

    q = group q by ('

    Account.Name

    ','StageName');

    q = foreach q generate '

    Account.Name', 'StageName', sum('sum_Amount') as 'sum_Amount',max(avg('relevant')) over([.. 0] partition by 'Account.Name

    ' order by 'StageName') as 'relevant';

    --filter only relevant Accounts

    q = filter q by 'relevant' > 0;

    --get rid of dummy data

    q = filter q by 'StageName' != "AAA";

0/9000

Hi,

 

I am trying to accomplish a left outer join in my dataflow and not getting the expected result. I have created two sample datasets like this:

 

Dataset Q: {A, B, C, D}

Dataset P: {(A,r), (A,s), (B,r), (B,s), (C,r), (C,s), (D,r), (D,s)}

 

Doing a left outer join on this in SQL returns the following:

 

Dataset QP: {(A,r), (A,s), (B,r), (B,s), (C,r), (C,s), (D,r), (D,s)}

 

Trying to do the same in my dataflow using an augment transformation (Dataset Q on the left, Dataset P on the right) with the lookup multiple values option returns this:

 

Dataset QP: {(A,(r,s)), (B,(r,s)), (C,(r,s)), (D,(r,s))}

 

Instead of returning multiple rows for multiple matches, it instead creates a multi-value field. Is it possible to get the results of a true left outer join in a dataflow or within an Einstein query so instead of creating a multi-value field, I instead get multiple rows returned per match?

2 comentários
  1. 4 de out. de 2020, 02:56

    Although I am afraid if I could not get you right, let me share my resolution with referring your sample.

    Set Column1 and Column2 which has {A,B,...} and {r, s,..} respectively.

    1. append

    DatasetQ & DatasetP with allowing disjoint schema

    2. ComputeRelative

    Partition by: Column1

    Order by: Column2 asc/desc

    Add a field (SAQL): Flg

     case when ('Column2' is null && previous('Column1') != previous('Column1') && next('Column1) != next('Column1')) || ('Column2' is not null) then "1" else "0" end

    3. Filter

    'Flg'=="1"

    Hope this work correctly in your case.

0/9000

Needing help with a YOY SAQL.  This is for a specific case of looking at current month and next 3 months, but viewing same data for last 4 years.  I have created the SAQL, but something is wrong with the count() result when joining all 4 streams.  Can anyone see what I have wrong here? I always get the count() data for the first query, but the others are zero (no matter what order they are in).  I'm sure it's something simple with using coalesce and count() together.  Thanks in advance...

q = load "AllInvoicesByDealer";

q = filter q by 'Order_Type' == "SY";

q = filter q by 'Account.Intl_Region_Name__c' == "1 - North America";

q1 = filter q by date('Invoice_Date1_Year', 'Invoice_Date1_Month', 'Invoice_Date1_Day') in ["current month - 1 year".."3 months ahead - 1 year"];

q2 = filter q by date('Invoice_Date1_Year', 'Invoice_Date1_Month', 'Invoice_Date1_Day') in ["current month - 2 years".."3 months ahead - 2 years"];

q3 = filter q by date('Invoice_Date1_Year', 'Invoice_Date1_Month', 'Invoice_Date1_Day') in ["current month - 3 years".."3 months ahead - 3 years"];

q4 = filter q by date('Invoice_Date1_Year', 'Invoice_Date1_Month', 'Invoice_Date1_Day') in ["current month - 4 years".."3 months ahead - 4 years"];

result = group q1 by ('Account.AccountOwner.Name', 'Invoice_Date1_Month', 'Invoice_Date1_Year') full, q2 by ('Account.AccountOwner.Name', 'Invoice_Date1_Month', 'Invoice_Date1_Year') full, q3 by ('Account.AccountOwner.Name', 'Invoice_Date1_Month', 'Invoice_Date1_Year') full, q4 by ('Account.AccountOwner.Name', 'Invoice_Date1_Month', 'Invoice_Date1_Year');

result = foreach result generate coalesce(q1.'Account.AccountOwner.Name', q2.'Account.AccountOwner.Name', q3.'Account.AccountOwner.Name', q4.'Account.AccountOwner.Name') as 'AccountOwner', coalesce(q1.'Invoice_Date1_Month', q2.'Invoice_Date1_Month', q3.'Invoice_Date1_Month',  

    q4.'Invoice_Date1_Month') as 'Invoice Month', coalesce(q1.'Invoice_Date1_Year', q2.'Invoice_Date1_Year', q3.'Invoice_Date1_Year',

    q4.'Invoice_Date1_Year') as 'Invoice_Year', coalesce(count(q1), count(q2), count(q3), count(q4), 0) as 'Systems';

result = order result by ('AccountOwner' asc, 'Invoice Month' asc, 'Invoice_Year' asc);

2 comentários
  1. 2 de out. de 2020, 00:24
    @Ludmilla Cunha Hi Ludmilla, yes, unfortunately it does not seem to support a specific time period with a YOY comparison. Our use case is to view next 3 calendar months, but in previous years. This is why my SAQL has "current month - 1 year".."3 months ahead - 1 year", -2 years, -3 years, etc. That data needs to be joined to be represented in a bar chart. But thanks for the suggestion!!
0/9000

Hi all,

 

I am facing issues with XMD in my sandbox on winter '21 preview:

  • When I try to make changes in SAQL and try to save the dashboard, I get the error "Found multiple measures with the same 'field' value : lens_2.<field name>
  • I tried to download a dataset xmd, make some changes and upload it back. However, I get an error asking me to check if it is in XMD 2.0 format. Corresponding article gives 404 error.

Can anyone help me with this issue? Thanks a ton!

3 comentários
  1. 22 de set. de 2020, 04:47
    There must still be validation problems in the XMD. Double check and search by Field name. Beyond that I'm not sure. It'S always been a little trial and error for me.
0/9000

Hi All, 

 

A basic one i assume for you guys here - trying to bind a stacked bar chart. I know how to bind two standard charts but can't seem to manage 2 stacked bar charts. What's the right way to go about this?

Cheers!

 

Kind Regards,

4 comentários
  1. 22 de ago. de 2020, 06:21

    I am afraid to ask you from me, not Peter...

    Have you specified "split" under "columnMap" section in Query?

    Like,

    "columnMap": {

    "trellis": [],

    "plots": [

    "somethingMeasure"

    ],

    "dimensionAxis": [

    "date_Quarter"

    ],

    "split": [

    "Pipeline"

    ]

    }

0/9000

I have a Snapshot dataflow running daily. I want to take this resulting dataset into another Dataflow and then add a filter to dynamically only look at the rows of data with a Snapshot date reflecting the 1st of the month. Any hints on the SAQL I could use for this? Thanks.

 

FYI @Gabriel Kacarab 

2 comentários
  1. 2 de jun. de 2020, 17:40
    Hi @Peter Lyons thank you. That resolved the issue. My syntax hapened to be 01 as you notated. I checked in a Lens. MY SAQL statement was as follows: Snapshot_Date_Day == "01"
0/9000