Skip to main content

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 commentaires
  1. 2 oct. 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