Monday, April 10, 2017

Wave example of dynamic groups, measures and charts

I have seen the request often enough to be able to change groups, measures and chart types based on your selections. This is beyond the scope of the normal filter/faceting that is immediately available. I wanted to post an example of how to use binding to build this solution. Because SAQL was not required exploration with the faceted results is still available. 


Links to download the full set of assets are available for download, however, please keep in mind that the dataset references, etc. will prevent you from being able to drop it in directly to work within your org. And all of this needs to be built using the flex dashboard designer.

To dynamically tailor the groups you need a selector and its binding.

            "Grouping_Selector": {
                "datasets": [],
                "dimensions": [],
                "isFacet": true,
                "selectMode": "singlerequired",
                "start": [
                    [
                        "CloseDate_Year"
                    ]
                ],
                "type": "static",
                "values": [
                    {
                        "value": [
                            "CloseDate_Year"
                        ],
                        "display": "Year"
                    },
                    {
                        "value": [
                            "CloseDate_Year",
                            "CloseDate_Quarter"
                        ],
                        "display": "Year and Quarter"
                    },
                    {
                        "value": [
                            "Region"
                        ],
                        "display": "Region"
                    },
                    {
                        "value": [
                            "Region",
                            "Account_State"
                        ],
                        "display": "Region and State"
                    },
                    {
                        "value": [
                            "StageName"
                        ],
                        "display": "Stage"
                    },
                    {
                        "value": [
                            [
                                "CloseDate_Year",
                                "CloseDate_Quarter"
                            ]
                        ],
                        "display": "Year - Quarter (NOT AVAIL, USE MEASURE SOLUTION)"
                    }
                ]

            },

Then include the binding in the groups section of your dashboard json

                    "groups": "{{ flatten(column(Grouping_Selector.selection, [\"value\"])).asObject() }}",


As another option we are loading the measure selections via CSV with the column headers:

axisMode,display,measure_comp_1,measure_comp_2,visualizationType

This dataset should be added to a list selector picking the "display" value.


            "listselector_3": {

                "parameters": {

                    "compact": false,

                    "exploreLink": false,

                    "instant": true,
                    "measureField": "count",
                    "step": "Measure_Selector",
                    "title": "Measure"
                },
                "type": "listselector"
            },


Then we create a selector based on the results of what was selected for the CSV:

            "Measure_Selections": {
                "datasets": [
                    {
                        "id": "0Fbf1000000QSeXCAW",
                        "label": "measure_info",
                        "name": "measure_info1",
                        "url": "/services/data/v39.0/wave/datasets/0Fbf1000000QSeXCAW"
                    }
                ],
                "isFacet": true,
                "isGlobal": false,
                "query": {
                    "measures": [
                        [
                            "count",
                            "*"
                        ]
                    ],
                    "groups": [
                        "measure_comp_1",
                        "measure_comp_2",
                        "axisMode",
                        "visualizationType"
                    ],
                    "filters": [
                        [
                            "display",
                            [
                                "{{ cell(Measure_Selector.selection, 0 , \"display\").asObject() }}"
                            ],
                            "in"
                        ]
                    ]
                },
                "selectMode": "single",
                "type": "aggregateflex",
                "useGlobal": true,
                "visualizationParameters": {
                    "visualizationType": "hbar",
                    "options": {}
                }
            },

Then the results of this step can update the measures dynamically as well as the chart type.

                    "measures": "{{ row(Measure_Selections.result, [], [\"measure_comp_1\", \"measure_comp_2\"]).asObject() }}",


And to be able to update the visualization


                    "axisMode": "{{ valueAt(row(Measure_Selections.result, [0], [\"axisMode\"]), 0).asString() }}",
                    "visualizationType": "{{ valueAt(row(Measure_Selections.result, [0], [\"visualizationType\"]), 0).asString() }}",



No comments:

Post a Comment