The WrapLinkAggregate widget

The WrapLinkAggregate widget performs mathematical operations over a group of wraps that fulfill certain criteria. Some of the more popular functions are SUM, MAX, MIN, AVERAGE and COUNT.

A common WrapLink uses a unique key to return a single value from a single wrap. If you need to aggregate values from all the wraps that match a particular condition, use the WrapLinkAggregate widget instead, and specify a non-unique key that matches more than one wrap.

Example: If you use a key that designates a particular depot for rolling stock, you can use the WrapLinkAggregate widget to obtain information such as:

  • The number of railway cars that require a certain maintenance operation.
  • The average time a similar maintenance operation has taken to perform in the past.
  • The anticipated working hours required to perform the pending maintenance.

The WrapLinkAggregate widget is often used to calculate key performance indicators. KPI data per day, week, month, or other periods can be automatically saved using a scheduling agent. Live data is updated on a regular basis so that your analysis is always based on fresh information. Historical data is securely preserved for long-term trend analysis.

With the basic format WrapLinkAggregate, you can use a Holder Cell to provide a dummy aggregate value (count, average, sum, etc) to test the wrap already in Excel. When the wrap is run on the server, WrapLinkAggregate extracts live data from the cloud database and returns the live, aggregated value in the holder cell. With the extended format WrapLinkAggregate2, a default value can be assigned directly in the function call, removing the need for a separate holder cell.

The WrapLinkAggregate widget is a visual guide that helps you insert a basic WrapLinkAggregate() function into the current cell. If you want to link to a Wrap that doesn’t yet exist on the Wrapsite, you need to insert the =wraplinkaggregate() function manually into the cell using the Function Reference section below. This is because the visual guide relies on the Wrapsite properties to provide a definition of the Wrap you want to link to, including its Unique Keys and the field you want to be aggregated. Without this information, the guide cannot give you much help anyway.

If you wish to use the extended WrapLinkAggregate2() function, you also need to insert the function manually into the cell using the Function Reference section below.

Extracting large amounts of data using MyWraps

Requesting a lot of data using many WrapLinks or WrapLinkAggregates, e.g. for a complex dashboard showing hundreds of entries, can be very time-consuming because of all the database operations required to provide the data one cell at a time. Using the MyWraps2 function, you can request a single data extract containing all the data you need by defining a single MyWraps link and having all the data returned with item separators in a single cell of the dashboard Wrap.

Insert a WrapLinkAggregate widget

  1. Select the cell where you want the WrapLinkAggregate widget to appear.
  2. Switch to the WrapCreator ribbon and click on Insert Widget.
  3. Select the WrapLinkAggregate widget on the Widget tab in the task pane.
  4. Enter the required parameters on the Cell tab and press Apply.
  5. Verify that a default value has been inserted into the cell.

Parameters

Screenshot of a WrapLinkAggregate widget

Cell name

We encourage you to assign cell names to calculated cells, so that they get correct headings in MyWraps reports. A convenient MapToNames tool can save time by automatically using the field label as the cell name.

Wrap Selector

Select the source wrap from which you want to pull data. If you have a database background, you can think of this as selecting a table.

Formula Builder

This section lets you specify all but one of the keys and values that together form the Unique Key that designates the wraps that you want to pull data from. To continue the database analogy, this key will select one or more rows in the source table. You must leave one key unselected – the resulting key must not be unique if it is to return values from more than one wrap.

As a developer, you may want to construct the key dynamically using runtime values from other cells in the wrap. You can insert cell references here or by editing the inserted wraplinkaggregate() function call as described below.

In the example above, the wrap link is assembled dynamically, using the field label in column D of the same row. The WrapLinkAggregate functions in column E always use the string “CL334_Delivery_” followed by the section name in column D:

  • In this case, D3 = Cleaning creates a link in E3 to CL334_Delivery_Cleaning.
  • In row 4, D4 = Cab, and the link in E4 points to CL334_Delivery_Cab.
  • With Pass_Saloon in D5, the link in E5 becomes CL334_Delivery_Pass_Saloon etc.

To clarify this, we expanded the list of existing wraps in the screenshot to make it easy to see the wraps names that correspond to the different section names.

Note the warning in red below the wrap selector. The formula has been manually edited in a way that isn’t supported by the wizard.

Aggregating

This section lets you select the “filter” cell in the source wraps that you want the WrapLinkAggregate to operate on (the column, if you think of the wrap as a table). After the call has been made, the aggregated value will be inserted in the cell where the =wraplinkaggregate() function call resides, and in the holder cell, if there is one.

Cell

Select the “filter” cell in the source wraps that you want the WrapLinkAggregate to operate on.

Cell Type

The Cell type is used to specify how the cell value will be handled. The prefix “sig-” means that you are extracting a value from a wrap signature cell.

Aggregate Function

Select the main function of the WrapLinkAggregate widget. For a description of the various aggregation functions, look up the corresponding function names in Excel.

Format Specifier

The format specifier is used to say how the calculated value will be displayed. For more information, study the Microsoft C# format specifiers. Examples:

  • f1 – fixed, one decimal
  • p1 – percent, one decimal

Holder cell

While you test the wrap in Excel, you can provide a test value in a special holder cell to verify that other formulas in the wrap return the correct results. When you upload the wrap, live data automatically replaces the test value in the holder cell. For a WrapLinkAggregate widget, the holder cell contains the results of the operation, e.g. the SUM or AVERAGE that was calculated over the selected wraps.

If you prefer to assign a default value in the function call instead, insert the function call manually using the extended WrapLinkAggregate2 format as described below.

Location

If you enable a holder cell for the widget, the cell immediately to the right of the WrapLinkAggregate widget is chosen by default. You can change the location of the holder cell by clicking on the “pen” symbol and then selecting a different cell as the holder cell.

Hidden

Holder cells sometimes contain information that you don’t want to show to the user of the wrap. In this case, tick this box to make the contents of the holder cell invisible in the wrap.

Dummy value

This is the value that the holder cell will contain during testing in Excel. When the wrap is running on the server, real values from the database are used, and the dummy value has no meaning. There are three possible types of values you can put here, depending on the situation:

  • If the server will return a number at runtime, the holder cell must contain a numeric value also during testing in Excel. Example: 100
  • If the server will return a text string, you must enter a text string here, and it must be delimited with double-quotes. Example: “JaneDoe”
  • If the server will return a timestamp, you must enter a timestamp in the OADate (or OADateTime) format used by OLE Automation, i.e. as a decimal number.

Special rules for timestamps

The OADate format is easy to handle for Excel developers because it is the same as an ordinary Excel serial number, i.e. the standard decimal number that Excel uses for timestamps internally.  The integer part counts the number of days and the decimal part tells the time of day. When you use an OADate in a holder cell, it must be formatted as a decimal number, not using a date or time format.

Read more about testing Wraps in Excel.

Openmode=fast

Wraps often link to each other. To provide the most recent information, linked wraps must be recalculated for every access to ensure that they in turn inherit the current values from their own linked wraps and return the most recent values to their caller.

Recalculation is normally instantaneous, but when a large number of wraps are affected by the same operation, e.g. a dashboard-style wrap that retrieves information from numerous other wraps, recalculating all the affected live wraps in a cascading fashion can have a noticeable effect on the wrap’s response time. Users must always wait for all the initiated recalculations to complete before the updated wrap appears on the screen.

In many cases, however, the information being gathered is historical. As an example, a dashboard of KPIs for the previous year, month, or week only reflects events in the past. For historical data, the recalculation of all the instances is unnecessary because the data never changes. It is good practice to freeze all wraps that no longer can change since it tells the system that they never again have to be recalculated.

Even with live wraps, the most recent changes can be irrelevant, which makes the recalculation unnecessary. You should open such wraps using the openmode=fast parameter in the link. With this option, all database operations will reuse the results from the most recent recalculation of each instance instead of recalculating it again, drastically reducing the response time when there are many links.

So, before any results are returned from a wrap:

  • If openmode=fast is in effect, and the wrap is live, cached data from the most recent recalculation is used.
  • Without openmode=fast, a live wrap is first recalculated, and all the live wraps it links to.
  • If a wrap has been frozen, its contents are static. Frozen wraps are never recalculated.

Results

Normal completion

The value in the source cell designated by the filter parameter is aggregated (sum, min, average, etc) for all wraps matching the link and the unique key. The result is copied into the target WrapLinkAggregate cell. The aggregated value is also copied into the holder cell, if any, to trigger any dependent calculations.

  • If you use the WrapLinkAggregate function, the aggregated value is also copied into the holder cell, if any, to trigger any dependent calculations. If you test a WrapLinkAggregate function within Excel, and a holder cell has been defined, the content of the holder cell is returned instead of live data. If no holder cell has been assigned in the function call, an empty string is returned.
  • The WrapLinkAggregate2 function does not support holder cells. If you test a WrapLinkAggregate2 function within Excel, the default value in the function call is returned instead of live data.

An undefined aggregation function was requested

If you request an undefined aggregation function in the WrapLinkAggregate formula, e.g. &function=BAD.f1, the WrapLinkAggregate displays a red “exclamation” icon.

  • The WrapLinkAggregate function returns an empty string.
  • The WrapLinkAggregate2 function returns its default value.

No filter specified

If you haven’t specified a filter parameter,

  • The WrapLinkAggregate function returns an empty string.
  • The WrapLinkAggregate2 function returns its default value.

The filter name is invalid

If the cell name in a filter parameter does not exist, the WrapLinkAggregate displays a red “not available” icon. Red circle icon used for a WrapLink where the filter cell is empty

  • The WrapLinkAggregate function returns an empty string.
  • The WrapLinkAggregate2 function returns its default value.

The filter is empty

If a wrap has an empty or null value in the source cell designated by the filter parameter, it will not be included in the aggregation. If no wraps return a usable value, the WrapLinkAggregate displays a red “not available” icon Red circle icon used for a WrapLink where the filter cell is empty

  • The WrapLinkAggregate function returns an empty string or zero depending on the data type.
  • The WrapLinkAggregate2 function returns its default value.

No wraps match the unique key

If you link to a group of wraps using a unique key that does not match any existing wraps in the database,

  • the WrapLinkAggregate function returns an empty string or zero depending on the data type.
  • the WrapLinkAggregate2 function returns its default value.

The wrap template does not exist

If the link points to a wrap that is not installed, a red “undefined” icon is displayed. Red X icon returned by a WrapLink that points to a wrap that is not installed or where the unique key combination is invalid

  • The WrapLinkAggregate function returns an empty string or zero depending on the data type.
  • The WrapLinkAggregate2 function returns its default value.

There is no link in the function call

If the link in the function call is empty, i.e. =WrapLinkAggregate(“”), nothing is displayed. This may be useful if you want to use an IF() statement inside the WrapLinkAggregate formula and return an empty link if the function shouldn’t be executed.

If there is no link in the function call,

  • the WrapLinkAggregate function returns an empty string.
  • The WrapLinkAggregate2 function returns its default value.

Read more under Conditional request below.

Linking to other wraps

In links, reserved characters must be encoded

One of the purposes of a WrapLink is to construct a valid hyperlink to another wrap. This link is a standard Uniform Resource Locator (URL) that contains your WrapSite’s name, a folder path, the name of the wrap, the names of the fields forming the key, and the filter name.

A URL must conform to certain rules, of which the most important is that the following characters have special meaning: ! * ‘ ( ) ; : @ & = + $ , / ? # [ ] Some of these characters are allowed in the names for Excel files, worksheets and cells, but we strongly recommend that you never use any of the reserved characters.

If you have a very special need to use one or more of the reserved characters (aside from their reserved meaning), they must be encoded. The reserved character /, for example, if used in the “folder path” component of a URL, has the special meaning of being a delimiter between folder names (path segments). If / needs to be used in a folder name, then you must percent-encode it to %2F or %2f instead of using the raw /. You can use the EncodeURL() function in Excel 2013 or later to percent-encode any names that may contain reserved characters.

Frozen wraps become static

If a wrap is frozen, any dynamic data pulled into the wrap using WrapLinks, WrapLinkLists, WrapLinkAggregates or MyWraps2 will no longer be updated. A frozen wrap always reflects exactly the conditions when it was frozen.

Avoid linking from hidden cells

Due to a design constraint, the WrapLink family of functions and MyWraps2 may not return the expected results for frozen wraps when placed in hidden cells. If you want to hide the result of a linking function, you should place it on a separate hidden sheet.

Update the Wrap Package regularly

Before you create your first wrap, you must install the Wrap Package that you downloaded from your wrapsite so that WrapCreator has all the information it needs about your wrapsite and how it is set up. The Wrap Package synchronizes Excel to your wrapsite and should be updated periodically to give WrapCreator access to the most recent wrap and user definitions.

Remove a WrapLinkAggregate widget

To delete a field, widget, wrap function or signature that has been stored at least once in the live production database is not a trivial task. The instructions below are only applicable during the initial development of a wrap, before it has ever been used in production. Read more about making changes to your wraps.

To remove a WrapLinkAggregate widget:

  1. Ensure that the task pane is visible.
  2. Select the widget’s cell.
  3. The task pane should now show the WrapLinkAggregate widget’s settings on the Cell tab. If it doesn’t, you may have selected the wrong cell, or already removed the widget by mistake.
  4. If the WrapLinkAggregate widget designates a holder cell, right-click on this cell and select Clear contents.
  5. In the settings for the WrapLinkAggregate widget, locate the Remove button at the bottom and click on it.

Function reference

Screenshot of a WrapLinkAggregate widget

Example

In the example above, the following cell formula is inserted in the cell.

=@WrapLinkAggregate("CL334_Redelivery_"&D3&"?reid="&ReID&IF($A$5="All";"";"&Unit="&$A$5)&"&Filter=reid.int&Function=COUNT")

As you can see, the developer has edited the formula to use cell references instead of static values. This example uses plain cell references like D3 and $A$5 because they are easier to use with Excel’s Fill Down.

The same technique works also with named cells. If a wrap has the mileage and car type in named cells you could use the following formula:

=@WRAPLINKAGGREGATE("Class395-Vehicle-PackPredictor?mileage=" & mileage & "&car=" & car_type & "&Filter=progress.percent&Function=MIN.f1")

Format and parameters

=@WRAPLINKAGGREGATE("link")
=@WRAPLINKAGGREGATE2("link", default_value)

link is a quoted text string that identifies the wrap you want to pull data from, provides the common key for the multiple wraps you are selecting, and what value you want to be returned from them. Read more below.

default_value provides a default value that the function returns in special cases described in the Results section above. The default value can also be used when you test the Wrap already in Excel. If no default value has been assigned in the function call, an empty string is returned. For the basic WrapLinkAggregate() function, this functionality is instead provided by a holder cell – read more below.

The different values that are returned by the function call are described in detail in the Results section above.

Link parameters

The parameters for a link are specified in the query string. The query string is appended to the wrap name following a question mark. Within the query string, parameters are separated by ampersands. In the second example above, the query string begins with a question mark and sends three parameters to the source wrap: mileage, car, and filter.

Wrap name

The link starts with the name of the wrap you want to link to, e.g. Class395-Vehicle-PackPredictor in the example above.

Components of the Key, e.g. mileage=, car=

The link must contain the Key that selects the group of wraps you want to pull data from. The Key is usually assembled from several values, e.g. for a bogie overhaul you would need to identify the car type and the mileage interval for the overhaul. You specify the components of the Key using the field names that the wrap is using for these values. In the second example above, the Key is provided by the mileage and car parameters.

Widening the scope

The WrapLinkAggregate Furmula Builder requires that you leave one key unselected. You can extend the scope of the aggregate by editing the formula and remove additional keys. In the example below, we removed the car parameter so that aggregation takes place over all car types.

=@WRAPLINKAGGREGATE("Class395-Vehicle-PackPredictor?mileage=" & mileage & "&Filter=progress.percent&Function=MIN.f1")
filter

The filter parameter returns a field value from the selected source wraps. The values in the field with this name are passed to the aggregation function and the result displayed in the same cell that the =wraplinkaggregate() formula occupies, and in the holder cell, if there is one.

function

Select the main function of the WrapLinkAggregate widget, e.g. function=COUNT. For a list of available functions, see the dropdown menu for the Aggregate Function setting for the widget. For a description of the various aggregation functions, look up the corresponding function names in Excel.

Format Specifier

The format specifier is used to say how the calculated value will be displayed. For more information, study the Microsoft C# format specifiers. Examples:

  • f1 – fixed, one decimal
  • p1 – percent, one decimal

The format specifier is an optional second part of the function parameter, preceded by a period. In the example above, the function=MIN.p1 setting means the function will return the lowest occurring value for the progress.percent field in the selection, and display it as xx.x%.

state=live | frozen | awaitingsignature | signedbyme | any

The state of a Wrap at any time is Live or Frozen. A WrapLinkAggregate can be restricted to live wraps only. If you specify state=live, the wrap will only select the wraps that have not been frozen.

Some live Wraps will be AwaitingSignature (waiting for the logged-in user to sign the wrap) or SignedByMe (when the signature has already been made). The state Any includes all Wraps.

=@WRAPLINKAGGREGATE("Class395-Vehicle-PackPredictor?mileage=" & mileage & &car=" & car_type & "&Filter=progress.percent&Function=MIN.p1&State=Live")
Conditional request

WrapLinkAggregate is a top-level function and cannot be nested inside another function like IF. If you want to make the function call only if a certain condition is True, you can place an IF statement around the link, and return an empty link to deactivate the function:

=WrapLinkAggregate(IF(required_field="","","link"))
Openmode=fast

When a Wrap only provides historical information, e.g. as a dashboard, you should always consider appending &openmode=fast to the link to it. This greatly increases performance. Read more under Openmode=fast above.

The holder cell

You can use a Holder Cell with the basic WralInkAggregate() function to provide a dummy aggregate value (count, average, sum, etc) to test the wrap already in Excel. When the wrap is run on the server, WrapLinkAggregate extracts live data from the cloud database and returns the live, aggregated value in the holder cell. The extended WrapLinkAggregate2() function does not support holder cells.

Format and parameters

=HOLDER(cell_name, dummy_value, hidden, holder_item)

cell_name points to the WrapLinkAggregate cell using its cell name.

dummy_value contains a value you want the cell to provide during testing in Excel – at runtime, real values from the server are used instead. The dummy value must have the same data type as the value that will later be returned by the server.

hidden if set to TRUE, makes the contents of the holder cell invisible in the wrap.

holder_item is always empty for WrapLinkAggregates.

=HOLDER(error_rate_avg, 0, TRUE, "")