KPIs

Interface patterns give you an opportunity to explore different interface designs. Be sure to check out How to Adapt a Pattern for Your Application.

Goal

The Key Performance Indicator ("KPI") patterns provide a common style and format for displaying important performance measures. This page explains how you can use this pattern in your interface, and walks through the design structure in detail.

The Key Performance Indicator (KPI) patterns provide a common style and format for displaying important performance measures. This page explains how you can use the three types of KPI patterns in your interface, and walks you through the design structure of the KPI 1 pattern in detail.

KPI patterns 1, 2, and 3 have the same functionality and user experience design. Test out all three to see which one aesthetically matches your business needs. The same set of data is used in a different way in each KPI pattern. All KPIs reflect how you can best use a single query to share related data across multiple components. Also, we've made it easy for you to delete one or more of the KPIs in each pattern if you need to show a different number of items.

The data that will be used in the KPIs will usually be either aggregated or sourced from a database view, since KPIs usually show single numbers aggregated across a business topic to show the success of an effort or initiative.

kpi_pattern_orig.png

Design Structure

The main components in this pattern are card layouts, rich text display fields and column layouts. The image below displays how the pattern looks on a blank interface with callouts of the main components. You can examine the entire expression or jump down to the subsections below with referenced line numbers to see a detailed breakdown of the main components.

In this design structure breakdown, we'll use KPI pattern 1 to explain how each component is used. You can drag and drop KPI 2 and 3 to see the same design, but with different colors and slightly different expression patterns.

KPI_pattern.png

Pattern Expression

When you drag and drop the grid with selection pattern onto your interface, 260 lines of expressions will be added to the section where you dragged it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
{
  a!localVariables(
    /* An array that contains prices for stocks, one for today and one for yesterday */
    /* This would typically be returned with a query */
    local!prices: {
      {id: 1, stockName: "S&P 500", todayPrice: (rand() * 500) + 1000, yesterdayPrice: (rand() * 500) + 1000},
      {id: 2, stockName: "NASDAQ", todayPrice: (rand() * 500) + 1000, yesterdayPrice: (rand() * 500) + 1000},
      {id: 3, stockName: "DOW JONES", todayPrice: (rand() * 500) + 1000, yesterdayPrice: (rand() * 500) + 1000},
      {id: 4, stockName: "NYSE", todayPrice: (rand() * 500) + 1000, yesterdayPrice: (rand() * 500) + 1000}
    },
    local!backgroundColor: "#1f3c8f",
    {
      a!columnsLayout(
        columns: {
          a!columnLayout(
            contents: {
              a!localVariables(
                local!sAndPData: local!prices[where(local!prices.stockName = {"S&P 500"})],
                a!cardLayout(
                  contents: {
                    a!richTextDisplayField(
                      label: "S&P 500",
                      value: {
                        a!richTextItem(
                          /* Displays the price for the current day */
                          text: fixed(local!sAndPData.todayPrice),
                          size: "LARGE"
                        )
                      }
                    ),
                    a!richTextDisplayField(
                      labelposition: "COLLAPSED",
                      value: {
                        /* This IF statement compares today's price to yesterday's price */
                        /* If the price went up, the icon is a caret-up; if it went down it is a caret-down */
                        if(
                          todecimal(local!sAndPData.todayPrice) > todecimal(local!sAndPData.yesterdayPrice),
                          a!richTextIcon(
                            icon: "caret-up",
                            color: "POSITIVE",
                            size: "MEDIUM"
                          ),
                          a!richTextIcon(
                            icon: "caret-down",
                            color: "NEGATIVE",
                            size: "MEDIUM"
                          )
                        ),
                        a!richTextItem(
                          /* This sets the text for the percent change section */
                          /* This includes the math for calculating the percent change */
                          text: concat(
                            fixed(todecimal(local!sAndPData.todayPrice) - todecimal(local!sAndPData.yesterdayPrice)),
                            " (",
                            round(100*(todecimal(local!sAndPData.todayPrice) - todecimal(local!sAndPData.yesterdayPrice))/todecimal(local!sAndPData.todayPrice),0),
                            "%) "
                          ),
                          /* This changes the color of the rich text to be POSITIVE or NEGATIVE depending on the price change */
                          color: if(
                            todecimal(local!sAndPData.todayPrice) > todecimal(local!sAndPData.yesterdayPrice) ,
                            "POSITIVE",
                            "NEGATIVE"
                          ),
                          size: "MEDIUM"
                        )
                      }
                    )
                  },
                  style: local!backgroundColor,
                  height: "AUTO"
                )
              )
            },
            width: "AUTO"
          ),
          a!columnLayout(
            contents: {
              a!localVariables(
                local!nasdaqData: local!prices[where(local!prices.stockName = {"NASDAQ"})],
                a!cardLayout(
                  contents: {
                    a!richTextDisplayField(
                      label: "NASDAQ",
                      value: {
                        a!richTextItem(
                          /* Displays the price for the current day */
                          text: fixed(local!nasdaqData.todayPrice),
                          size: "LARGE"
                        )
                      }
                    ),
                    a!richTextDisplayField(
                      labelposition: "COLLAPSED",
                      value: {
                        /* This IF statement compares today's price to yesterday's price */
                        /* If the price went up, the icon is a caret-up; if it went down it is a caret-down */
                        if(
                          todecimal(local!nasdaqData.todayPrice) > todecimal(local!nasdaqData.yesterdayPrice),
                          a!richTextIcon(
                            icon: "caret-up",
                            color: "POSITIVE",
                            size: "MEDIUM"
                          ),
                          a!richTextIcon(
                            icon: "caret-down",
                            color: "NEGATIVE",
                            size: "MEDIUM"
                          )
                        ),
                        a!richTextItem(
                          /* This sets the text for the percent change section */
                          /* This includes the math for calculating the percent change */
                          text: concat(
                            fixed(todecimal(local!nasdaqData.todayPrice) - todecimal(local!nasdaqData.yesterdayPrice)),
                            " (",
                            round(100*(todecimal(local!nasdaqData.todayPrice) - todecimal(local!nasdaqData.yesterdayPrice))/todecimal(local!nasdaqData.todayPrice),0),
                            "%) "
                          ),
                          /* This changes the color of the rich text to be POSITIVE or NEGATIVE depending on the price change */
                          color: if(
                            todecimal(local!nasdaqData.todayPrice) > todecimal(local!nasdaqData.yesterdayPrice) ,
                            "POSITIVE",
                            "NEGATIVE"
                          ),
                          size: "MEDIUM"
                        )
                      }
                    )
                  },
                  style: local!backgroundColor,
                  height: "AUTO"
                )
              )
            }
          ),
          a!columnLayout(
            contents: {
              a!localVariables(
                local!dowJonesData: local!prices[where(local!prices.stockName = {"DOW JONES"})],
                a!cardLayout(
                  contents: {
                    a!richTextDisplayField(
                      label: "DOW JONES",
                      value: {
                        a!richTextItem(
                          /* Displays the price for the current day */
                          text: fixed(local!dowJonesData.todayPrice),
                          size: "LARGE"
                        )
                      }
                    ),
                    a!richTextDisplayField(
                      labelposition: "COLLAPSED",
                      value: {
                        /* This IF statement compares today's price to yesterday's price */
                        /* If the price went up, the icon is a caret-up; if it went down it is a caret-down */
                        if(
                          todecimal(local!dowJonesData.todayPrice) > todecimal(local!dowJonesData.yesterdayPrice),
                          a!richTextIcon(
                            icon: "caret-up",
                            color: "POSITIVE",
                            size: "MEDIUM"
                          ),
                          a!richTextIcon(
                            icon: "caret-down",
                            color: "NEGATIVE",
                            size: "MEDIUM"
                          )
                        ),
                        a!richTextItem(
                          /* This sets the text for the percent change section */
                          /* This includes the math for calculating the percent change */
                          text: concat(
                            fixed(todecimal(local!dowJonesData.todayPrice) - todecimal(local!dowJonesData.yesterdayPrice)),
                            " (",
                            round(100*(todecimal(local!dowJonesData.todayPrice) - todecimal(local!dowJonesData.yesterdayPrice))/todecimal(local!dowJonesData.todayPrice),0),
                            "%) "
                          ),
                          /* This changes the color of the rich text to be POSITIVE or NEGATIVE depending on the price change */
                          color: if(
                            todecimal(local!dowJonesData.todayPrice) > todecimal(local!dowJonesData.yesterdayPrice),
                            "POSITIVE",
                            "NEGATIVE"
                            ),
                          size: "MEDIUM"
                        )
                      }
                    )
                  },
                  style: local!backgroundColor,
                  height: "AUTO"
                )
              )
            }
          ),
          a!columnLayout(
            contents: {
              a!localVariables(
                local!nyseData: local!prices[where(local!prices.stockName = {"NYSE"})],
                a!cardLayout(
                  contents: {
                    a!richTextDisplayField(
                      label: "NYSE",
                      value: {
                        a!richTextItem(
                          /* Displays the price for the current day */
                          text: fixed(local!nyseData.todayPrice),
                          size: "LARGE"
                        )
                      }
                    ),
                    a!richTextDisplayField(
                      labelposition: "COLLAPSED",
                      value: {
                        /* This IF statement compares today's price to yesterday's price */
                        /* If the price went up, the icon is a caret-up; if it went down it is a caret-down */
                        if(
                          todecimal(local!nyseData.todayPrice) > todecimal(local!nyseData.yesterdayPrice) ,
                          a!richTextIcon(
                            icon: "caret-up",
                            color: "POSITIVE",
                            size: "MEDIUM"
                          ),
                          a!richTextIcon(
                            icon: "caret-down",
                            color: "NEGATIVE",
                            size: "MEDIUM"
                          )
                        ),
                        a!richTextItem(
                          /* This sets the text for the percent change section */
                          /* This includes the math for calculating the percent change */
                          text: concat(
                            fixed(todecimal(local!nyseData.todayPrice) - todecimal(local!nyseData.yesterdayPrice)),
                            " (",
                            round(100*(todecimal(local!nyseData.todayPrice) - todecimal(local!nyseData.yesterdayPrice))/todecimal(local!nyseData.todayPrice),0),
                            "%) "
                          ),
                          /* This changes the color of the rich text to be POSITIVE or NEGATIVE depending on the price change */
                          color: if(
                            todecimal(local!nyseData.todayPrice) > todecimal(local!nyseData.yesterdayPrice) ,
                            "POSITIVE",
                            "NEGATIVE"
                            ),
                          size: "MEDIUM"
                        )
                      }
                    )
                  },
                  style: local!backgroundColor,
                  height: "AUTO"
                )
              )
            }
          )
        }
      )
    }
  )
}

[Line 1-11] Define Prices and Background Color

At the top of the pattern, local variables set up a common color used by all the card layouts, as well as the data that will be used in the KPIs.

1
2
3
4
5
6
7
8
9
10
11
{
  a!localVariables(
    /* An array that contains prices for stocks, one for today and one for yesterday */
    /* This would typically be returned with a query */
    local!prices: {
      {id: 1, stockName: "S&P 500", todayPrice: (rand() * 500) + 1000, yesterdayPrice: (rand() * 500) + 1000},
      {id: 2, stockName: "NASDAQ", todayPrice: (rand() * 500) + 1000, yesterdayPrice: (rand() * 500) + 1000},
      {id: 3, stockName: "DOW JONES", todayPrice: (rand() * 500) + 1000, yesterdayPrice: (rand() * 500) + 1000},
      {id: 4, stockName: "NYSE", todayPrice: (rand() * 500) + 1000, yesterdayPrice: (rand() * 500) + 1000}
    },
    local!backgroundColor: "#1f3c8f",

[Line 12-75] Use a Card Layout in a Column Layout to Display KPIs

The first visible component is a card layout in a column layout with the label of "S&P 500" in a rich text display field. For this particular KPI, we use an if() statement to compare price today and yesterday to decide whether a caret-up or a caret-down is displayed. We then use another rich text item to display the percentage change. Some math is involved with calculating this percentage, followed by an if() statement that changes the color of the rich text depending on whether the percentage is a negative or positive number. This kind of conditional styling based on the data being displayed is recommended to make it easy for the viewer to quickly understand the data in each KPI.

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
   {
      a!columnsLayout(
        columns: {
          a!columnLayout(
            contents: {
              a!localVariables(
                local!sAndPData: local!prices[where(local!prices.stockName = {"S&P 500"})],
                a!cardLayout(
                  contents: {
                    a!richTextDisplayField(
                      label: "S&P 500",
                      value: {
                        a!richTextItem(
                          /* Displays the price for the current day */
                          text: fixed(local!sAndPData.todayPrice),
                          size: "LARGE"
                        )
                      }
                    ),
                    a!richTextDisplayField(
                      labelposition: "COLLAPSED",
                      value: {
                        /* This IF statement compares today's price to yesterday's price */
                        /* If the price went up, the icon is a caret-up; if it went down it is a caret-down */
                        if(
                          todecimal(local!sAndPData.todayPrice) > todecimal(local!sAndPData.yesterdayPrice),
                          a!richTextIcon(
                            icon: "caret-up",
                            color: "POSITIVE",
                            size: "MEDIUM"
                          ),
                          a!richTextIcon(
                            icon: "caret-down",
                            color: "NEGATIVE",
                            size: "MEDIUM"
                          )
                        ),
                        a!richTextItem(
                          /* This sets the text for the percent change section */
                          /* This includes the math for calculating the percent change */
                          text: concat(
                            fixed(todecimal(local!sAndPData.todayPrice) - todecimal(local!sAndPData.yesterdayPrice)),
                            " (",
                            round(100*(todecimal(local!sAndPData.todayPrice) - todecimal(local!sAndPData.yesterdayPrice))/todecimal(local!sAndPData.todayPrice),0),
                            "%) "
                          ),
                          /* This changes the color of the rich text to be POSITIVE or NEGATIVE depending on the price change */
                          color: if(
                            todecimal(local!sAndPData.todayPrice) > todecimal(local!sAndPData.yesterdayPrice) ,
                            "POSITIVE",
                            "NEGATIVE"
                          ),
                          size: "MEDIUM"
                        )
                      }
                    )
                  },
                  style: local!backgroundColor,
                  height: "AUTO"
                )
              )
            },
            width: "AUTO"
          ),

The remaining three KPIs in lines 76 through 260 follow the same pattern as the first KPI to determine the percentage and color.

FEEDBACK