Sunday, March 26, 2017

Derived Fields in Wave Dataflows using case statements- sample syntax to use

The following dataflow loads an existing dataset, adds derived fields thru a computeExpression node and merges with the source node, then registers the result in a new dataset. notice the combination of condition statements used and syntax.

{

 "z-1": {
    "action": "edgemart",
    "parameters": {
      "alias": "Leads5"
    }
  },
  "z-2": {
    "action": "computeExpression",
    "parameters": {
      "source": "z-1",
      "mergeWithSource": true,
      "computedFields": [
        {
          "name": "CaseStatus",
          "type": "Text",
          "label": "Case Status",
          "saqlExpression": " case  when 'Status' == \"Open\" && 'Include_Flag' == 1 then \"Open\" when 'Status' == \"Closed\"  then \"Closed\"   else \"Other\"  end"
        },
        {
          "name": "CustomOrderedTimeBucket",
          "type": "Text",
          "saqlExpression": " case  when 'Elapsed_Days' == \"NOACTVTY\" then \"0. NOACTVTY\"  when 'Elapsed_Days' == \"GT12MO\" then \"1. >12Mon\" when 'Elapsed_Days' == \"6to12MO\" then \"2. 6to12Mon\" when 'Elapsed_Days' == \"2to6MO\" then \"3. 2to6Mon\"   when 'Elapsed_Days' == \"1MO\" then \"4. 1Mon\" else \"5. Other\" end"
        },
        {
          "name": "CaseAge",
          "label": "CaseAge",
          "type": "Text",
          "saqlExpression": " case  when date('CreatedDate_Year', 'CreatedDate_Month', 'CreatedDate_Day') in [dateRange([2016,1,1], [2016,12,31])]  then \"2016 Bucket\"  else \"Older\"  end "
        }
      ]
    }
  },
  "z-3": {
    "action": "sfdcRegister",
    "parameters": {
      "alias": "finalZdataset",
      "name": "finalZdataset",
      "source": "z-2"
    }
  }
}






Thursday, March 23, 2017

How to limit rows or filter data being pulled from Salesforce Objects to Datasets (specifically on sfdcdigest node)

There are cases where you might want to limit the rows being read from a salesforce object (for example Leads) in a sfdcdigest node in the dataflow. For that, you can use the following:

1- for simple filtering on text or numeric values, use this syntax:

{
    "z-1": {
        "action": "sfdcDigest",
        "parameters": {
            "object": "Lead",
            "fields": [
             
                {
                    "name": "Id"
                },
                {
                    "name": "Division"
                },

                {
                    "name": "BillingDate"
                }
            ],
            "filterConditions" : [
            {
               "field": "Division",
               "operator": "LIKE",
               "value": "Ship01%"
            },
            {
                "field": "FiscalQuarter",
                "operator": "!=",
                "value": "2"
            }
            ]
   },
"z-2": {
      "action": "sfdcRegister",
      "parameters": {
         "alias": "MyFilteredDataset",
         "name": "MyFilteredDataset",
         "source": "z-1"
}
}


note that the operator can by =, <, >, INCLUDES, EXCLUDES, etc... for full list and details check this link:
https://resources.docs.salesforce.com/206/latest/en-us/sfdc/pdf/bi_admin_guide_data_integration_guide.pdf


2- for complex filtering (leveraging a SOQL 'Where' clause to filter the extracted sfdc object), here is an an example (filtering by CreateDate):

{
    "z-1": {
        "action": "sfdcDigest",
        "parameters": {
            "object": "Lead",
            "fields": [
             
                {
                    "name": "Id"
                },
                {
                    "name": "Division"
                },

                {
                    "name": "BillingDate"
                }
            ],
              "complexFilterConditions": "(BillingDate >= 2016-01-01T00:00:00.000Z) AND (BillingDate < 2017-01-01T00:00:00.000Z)"
        }
   },
"z-2": {
      "action": "sfdcRegister",
      "parameters": {
         "alias": "MyFilteredDataset",
         "name": "MyFilteredDataset",
         "source": "z-1"
}
}



Monday, March 13, 2017

Is there a way to show up and down arrows with colors on a widget in a wave dashboard?

Here is a cool example how @terence.wilson came up with up and down arrows for widget display:
(PS: at this point in time, it does require some saql editing)




1-first here are the buttons :  ▲  , ▼  ,  and ◄ ►   (you can copy and paste in the case statement directly - no need to lookup the shortcut keyboard keys)
2-you need to create a SAQL step to produce the desired outcome (the arrows) using a case statement: alternatively you can apply this in the dataflow using a saqlexpression:
(case when 'perc_Roll' > 0 then \"▲\" when  'perc_Roll' < 0 then \"▼\"  else \"◄ ►\" end) as 'diff_arrow')
3-utilize the outcome of the saql step in a binding example in a text widget:
(
            "text_1": {
                "parameters": {
                    "fontSize": 24,
                    "text": "{{coalesce(cell(housepurchase_Roll_7on7.result, 0, \"diff_arrow\"),\"◄ ►\" ).asString()}}",
                    "textAlignment": "left",
                    "textColor": "#9271E8"
                },
                "type": "text"
            },
)