Example: Using the DATASOURCE function with the ARRAY function

The following example demonstrates how to use the DATASOURCE function with the ARRAY function.

The final Klips allow a user to either select data source 1 (DS1) or data source 2 (DS2) from a drop down menu. Depending on what is selected, the corresponding value in cell A2 is displayed, either 11585 or 22585. Although this example uses a value component, this concept can be used with other Klipfolio components.

Prerequisite

You must know the DATASOURCE id of your data sources. For more information about obtaining the DATASOURCE id, see DATASOURCE function. Both data sources must be in the same format.

This example uses the following data sets for the DS1 data source and the DS2 data source.

A

ga:visits
11585

A

ga:visits
22585

Step 1: Configuring the User Input Control component

  1. Create a User Input Control component (Don't use a data source). For more information, see How to build User Input Control components.
  2. In the Klip Editor workspace, select the Klip node, and give your Klip a name.
  3. Select the Drop-Down List from the component tree.
  4. From the Properties Panel, provide the following information:
    • Control Label:. For example, Choose your data source.
    • Create New Variable:. For example, datasource_variable_name.

      For more information about creating a variable, see Variables.

    • Scope: Dashboard

      Change to Klip only for a multi-component Klip.

  5. Select Values from the component tree.

Location

Action

For our example

From the formula editing toolbar. Select Insert function, ARRAY ARRAY( data )
With data selected. Select Insert literal string or number, paste in the datasource id for DS1, and click the Apply button. ARRAY( b9d641343b60e92af1da323eb3ec2820 , data )
With data selected. Select Insert literal string or number, paste in the datasource id for DS2, and click the Apply button. ARRAY( b9d641343b60e92af1da323eb3ec2820 , 30adf78dfe69821cd78e45067e453230 , data )
  1. Select Labels from the component tree.

Location

Action

For our example

From the formula editing toolbar. Select Insert function, ARRAY. ARRAY( data )
With data selected. Select Insert literal string or number, enter DS1, and click the Apply button. ARRAY( "DS1" , data )
With data selected. Select Insert literal string or number, enter DS2, and click the Apply button. ARRAY( "DS1" , "DS2" , data )

Step 2: Configuring the Value component

  1. Create a Value component (Don't use a data source). For more information, see How to build Value Pair components.
  2. In the Klip Editor workspace, select the Klip node, and give your Klip a name.
  3. Select Primary Value from the component tree.
  4. Select the Data panel.
  5. Location

    Action

    For our example

    From the formula editing toolbar. Select Insert function, Data Manipulation, DATASOURCE. DATASOURCE( datasource id , pointer)
    With datasource id selected. Select Insert variable and select datasource_variable_name. DATASOURCE( datasource_variable_name , pointer )
    With pointer selected. Select Insert literal string or number, type in your datasource cell reference, and click the Apply button. DATASOURCE ( datasource_variable_name, "A2" )

Feedback and Knowledge Base