Example: Using the DATASOURCE function with the SWITCH function

The following example demonstrates how to use the DATASOURCE function with the SWITCH 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 for the data sources. For more information about obtaining the data source 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_name2.

      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.

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.

 SWITCH ( datasource_variable_name2, "DS1", DATASOURCE( b9d641343b60e92af1da323eb3ec2820, "A2" ) , "DS2", DATASOURCE( 30adf78dfe69821cd78e45067e453230, "A2") case , value )