Measure and Group Bindings in Compact-Form and SAQL-Form Queries

You can use bindings in compact-form queries and SAQL-form queries.

Let’s look at an example where the selections in two custom queries (StaticSAQLMeasureNames and StaticSAQLGroupingNames) determine the measure and grouping of a SAQL-form query. Notice that the bindings for both measures and groups are defined in two places. To learn more about strings, numbers, and groups fields, see SAQL Step Type Properties.

1{
2    "label": "New dashboard",
3    "mobileDisabled": false,
4    "state": {
5        "steps": {
6            "lens_1": {
7                "type": "saql",
8                "query": "q = load \"OpportunityWithAccount\";\nq = group q by {{column(StaticSAQLGroupingNames.selection, [\"value\"]).asGrouping()}};\nq = foreach q generate {{row(StaticSAQLGroupingNames.selection, [], [\"expression\", \"alias\"]).asProjection()}}, {{row(StaticSAQLMeasureNames.selection, [], [\"expression\", \"alias\"]).asProjection()}};\nq = order q by ‘AccountId.Industry’ asc;\nq = limit q 2000;",
9                "useGlobal": true,
10                "numbers": "{{column(StaticSAQLMeasureNames.selection, [\"alias\"]).asObject()}}",
11                "groups": "{{column(StaticSAQLGroupingNames.selection, [\"alias\"]).asObject()}}",
12                "strings": "{{column(StaticSAQLGroupingNames.selection, [\"alias\"]).asObject()}}",
13                "visualizationParameters": {},
14                "selectMode": "single",
15                "broadcastFacet": true,
16                "receiveFacetSource": {
17                    "mode": "all",
18                    "steps": []
19                }
20            },
21            "StaticSAQLMeasureNames": {
22                "datasets": [],
23                "dimensions": [],
24                "isFacet": true,
25                "isGlobal": false,
26                "selectMode": "singlerequired",
27                "start": {
28                    "display": [
29                        "Total Amount"
30                    ]
31                },
32                "type": "staticflex",
33                "useGlobal": true,
34                "values": [
35                    {
36                        "display": "Total Amount",
37                        "cf": [
38                            "sum",
39                            "Amount"
40                        ],
41                        "expression": "sum(‘Amount’)",
42                        "alias": "sum_Amount"
43                    },
44                    {
45                        "display": "Avg Amount",
46                        "cf": [
47                            "avg",
48                            "Amount"
49                        ],
50                        "expression": "avg(‘Amount’)",
51                        "alias": "avg_Amount"
52                    }
53                ],
54                "numbers": [],
55                "strings": [],
56                "groups": [],
57                "columns": {},
58                "broadcastFacet": true
59            },
60            "StaticSAQLGroupingNames": {
61                "datasets": [],
62                "dimensions": [],
63                "isFacet": true,
64                "isGlobal": false,
65                "selectMode": "multirequired",
66                "start": {
67                    "display": [
68                        "Country"
69                    ]
70                },
71                "type": "staticflex",
72                "useGlobal": true,
73                "values": [
74                    {
75                        "display": "Industry",
76                        "value": "AccountId.Industry",
77                        "expression": "‘AccountId.Industry’",
78                        "alias": "AccountId.Industry"
79                    },
80                    {
81                        "display": "Source",
82                        "value": "AccountId.AccountSource",
83                        "expression": "‘AccountId.AccountSource’",
84                        "alias": "AccountId.AccountSource"
85                    }
86                ],
87                "numbers": [],
88                "strings": [],
89                "groups": [],
90                "columns": {},
91                "broadcastFacet": true
92            }
93        },
94        "widgets": {
95            "pillbox_3": {
96                "type": "pillbox",
97                "parameters": {
98                    "compact": false,
99                    "showActionMenu": true,
100                    "exploreLink": false,
101                    "fontSize": 14,
102                    "textColor": "#0070D2",
103                    "selectedTab": {
104                        "textColor": "#FFFFFF",
105                        "backgroundColor": "#0070D2",
106                        "borderEdges": [
107                            "all"
108                        ],
109                        "borderColor": "#C6D3E1",
110                        "borderWidth": 1
111                    },
112                    "step": "StaticSAQLGroupingNames"
113                }
114            },
115            "pillbox_4": {
116                "type": "pillbox",
117                "parameters": {
118                    "compact": false,
119                    "showActionMenu": true,
120                    "exploreLink": false,
121                    "fontSize": 14,
122                    "textColor": "#0070D2",
123                    "selectedTab": {
124                        "textColor": "#FFFFFF",
125                        "backgroundColor": "#0070D2",
126                        "borderEdges": [
127                            "all"
128                        ],
129                        "borderColor": "#C6D3E1",
130                        "borderWidth": 1
131                    },
132                    "step": "StaticSAQLMeasureNames"
133                }
134            },
135            "chart_1": {
136                "type": "chart",
137                "parameters": {
138                    "visualizationType": "hbar",
139                    "title": {
140                        "label": "",
141                        "fontSize": 14,
142                        "subtitleLabel": "",
143                        "subtitleFontSize": 11,
144                        "align": "center"
145                    },
146                    "theme": "wave",
147                    "showValues": true,
148                    "axisMode": "multi",
149                    "autoFitMode": "keepLabels",
150                    "binValues": false,
151                    "bins": {
152                        "breakpoints": {
153                            "low": 0,
154                            "high": 100
155                        },
156                        "bands": {
157                            "low": {
158                                "label": "",
159                                "color": "#B22222"
160                            },
161                            "medium": {
162                                "label": "",
163                                "color": "#FFA500"
164                            },
165                            "high": {
166                                "label": "",
167                                "color": "#008000"
168                            }
169                        }
170                    },
171                    "dimensionAxis": {
172                        "showAxis": true,
173                        "showTitle": true,
174                        "title": "",
175                        "customSize": "auto",
176                        "icons": {
177                            "useIcons": false,
178                            "iconProps": {
179                                "column": "",
180                                "fit": "cover",
181                                "type": "round"
182                            }
183                        }
184                    },
185                    "measureAxis1": {
186                        "sqrtScale": false,
187                        "showAxis": true,
188                        "customDomain": {
189                            "showDomain": false
190                        },
191                        "showTitle": true,
192                        "title": ""
193                    },
194                    "measureAxis2": {
195                        "sqrtScale": false,
196                        "showAxis": true,
197                        "customDomain": {
198                            "showDomain": false
199                        },
200                        "showTitle": true,
201                        "title": ""
202                    },
203                    "legend": {
204                        "show": true,
205                        "showHeader": true,
206                        "inside": false,
207                        "descOrder": false,
208                        "position": "right-top",
209                        "customSize": "auto"
210                    },
211                    "tooltip": {
212                        "customizeTooltip": false,
213                        "showDimensions": true,
214                        "dimensions": "",
215                        "showMeasures": true,
216                        "measures": "",
217                        "showPercentage": true,
218                        "showNullValues": true,
219                        "showBinLabel": true
220                    },
221                    "trellis": {
222                        "enable": false,
223                        "showGridLines": true,
224                        "flipLabels": false,
225                        "type": "x",
226                        "chartsPerLine": 4,
227                        "size": [
228                            100,
229                            100
230                        ]
231                    },
232                    "applyConditionalFormatting": true,
233                    "showActionMenu": true,
234                    "exploreLink": true,
235                    "step": "lens_1"
236                }
237            }
238        },
239        "filters": [],
240        "gridLayouts": [
241            {
242                "name": "Default",
243                "numColumns": 12,
244                "rowHeight": "normal",
245                "version": 1,
246                "pages": [
247                    {
248                        "label": "Untitled",
249                        "name": "36d03d4a-cdce-427e-b338-4ae29db1ba26",
250                        "widgets": [
251                            {
252                                "row": 0,
253                                "column": 6,
254                                "rowspan": 2,
255                                "colspan": 6,
256                                "name": "pillbox_3",
257                                "widgetStyle": {}
258                            },
259                            {
260                                "row": 2,
261                                "column": 6,
262                                "rowspan": 2,
263                                "colspan": 6,
264                                "name": "pillbox_4",
265                                "widgetStyle": {}
266                            },
267                            {
268                                "row": 0,
269                                "column": 0,
270                                "rowspan": 4,
271                                "colspan": 6,
272                                "name": "chart_1",
273                                "widgetStyle": {}
274                            }
275                        ],
276                        "navigationHidden": false
277                    }
278                ],
279                "selectors": [],
280                "style": {
281                    "backgroundColor": "#F2F6FA",
282                    "gutterColor": "#C5D3E0",
283                    "cellSpacingX": 8,
284                    "cellSpacingY": 8,
285                    "fit": "original",
286                    "alignmentX": "left",
287                    "alignmentY": "top"
288                }
289            }
290        ],
291        "dataSourceLinks": [],
292        "widgetStyle": {
293            "backgroundColor": "#FFFFFF",
294            "borderEdges": [],
295            "borderColor": "#E6ECF2",
296            "borderWidth": 1,
297            "borderRadius": 0
298        }
299    },
300    "datasets": [
301        {
302            "id": "Edgemart13",
303            "name": "OpportunityWithAccount",
304            "label": "Opportunity With Accounts",
305            "url": "../../WaveCommon/repo/edgemarts/OpportunityWithAccount/OpportunityWithAccountEM"
306        }
307    ]
308}

If you bind a measure or grouping in a compact-form or SAQL-form step used for a chart, you must also replace the columnMap section in the widget-level chart JSON with an empty columns array. For more information, see Measure Interactions and Group Interactions.

Note

If you provide an aggregate function for a measure, then the measure value must be a string, not an array.

Note