Pages

Monday, March 23, 2020

Einstein Analytics: using Flatten node to get Account Parent

Here is our scenario, we have multi-level account hierarchy, the sample of accounts for this blog:



Use case 1: display all child accounts (including top parent account) and their opportunities when the top parent is selected.

Dataflow:


We need to manually edit the Flatten node from JSON, by default, the Multi Field and Path Field fields are created as system fields, which aren’t visible in the user interface. To make the fields appear in the user interface and dataflow, add a schema section to the flatten transformation and set the IsSystemField metadata attribute to false for each field in the transformation.

"Flatten_UltimateParent": {
    "schema": {
      "objects": [
        {
          "label": "Flatten_UltimateParent",
          "fields": [
            {
              "name": "UltimateParentPath",
              "label": "UltimateParentPath",
              "isSystemField": false
            },
            {
              "name": "AccountParentIds",
              "label": "AccountParentIds",
              "isSystemField": false
            }
          ]
        }
      ]
    },
    "action": "flatten",
    "parameters": {
      "include_self_id": true,
      "multi_field": "AccountParentIds",
      "path_field": "UltimateParentPath",
      "source": "getAccount",
      "self_field": "Id",
      "parent_field": "ParentId"
    }
  }


Unfortunately, we will not see the schema in the dataflow UI.

We also need to Connect Data Source between Account and Opportunity using the Ultimate Parent Name.



Here is the dashboard:



Note:

1) Multi_Field from the flatten nodes will contain self Account Id (we select "Include Self ID" in the flatten node) and all the parents' Id.

Notice that top Parent Id 0018000001BNnOPAA1 is stored in ALL hierarchy, while Account F Id only stored on itself Account F and it child Account G. Don't be trick when AccountParentIds only show 1 value, because this is a multi-values field.

2) Path_Field will show all hierarchy from self Id, up to parent Id, and all the way to the top level.

* I use "Image" (under Show Data As) to show the full length of field content of UltimateParentPath column


Use case 2: display all accounts (including the child accounts) and their opportunities (including from their child accounts) when an Account is selected, the account could be on the top, middle, or bottom level in the account hierarchy.

Dataflow: let us modify existing dataflow to below:



We just need to add an augment node Account Name from Multi_Field AccountParentIds.



You also need to Connect Data Source between Account and Opportunity using the Account Parent Name from the augment node.



Here is the dashboard:



When select Account F, the dashboard will filter to Account F and the child accounts.


Referenceflatten Parameters



8 comments:

  1. Thanks Johan, I was looking for the second use case, well explained thanks.

    ReplyDelete
  2. Hi Johan, I am trying to do something similarish, but a little different. I want to see all accounts and their contacts with their ACR information as well.

    Would i do somehing similar?

    (I don't have a lot of experience with dataflows, know the basics, but have definitely
    been surviving on using recipes majority of the time)

    ReplyDelete
    Replies
    1. In a hierarchy? if yes, use Flatten nodes should works

      Delete
  3. Thanks for the response. Yes in the hierarchy.

    I would like the user to have a filter, and when they choose a certain account, it then shows all the other accounts in that hierarchy

    ReplyDelete
    Replies
    1. Yes, that should be possible and very similar with this blog

      Delete
  4. Hi, Which field is UltimateParent field in the JSON structure, there are only UltimatePareentPath? could you please with this? Thanks

    ReplyDelete
    Replies
    1. have you check the JSON file? https://na89.salesforce.com/sfc/p/#300000000SHq/a/2J000000VTje/XtMieEb5gkm7lZ8.a8iUfWMeQUEJL2GHR3a3ckN.84I

      Delete

Page-level ad