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.

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 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, Logic, SWITCH. SWITCH ( data , case, value )
    With data selected. Select Insert variable and and select the variable you created earlier (datasource_variable_name2). SWITCH ( datasource_variable_name2, case , value )
    With case selected. Select Insert literal string or number, type in DS1, and click the Apply button. SWITCH ( datasource_variable_name2, "DS1", value )
    With value selected. Select Insert function, Data Manipulation, DATASOURCE. SWITCH ( datasource_variable_name2, "DS1" , DATASOURCE( datasource_id , pointer ) case , value )
    With datasource_id selected. Select Insert literal string or number, paste in the datasource id for DS1, and click the Apply button. SWITCH ( datasource_variable_name2, "DS1", DATASOURCE( b9d641343b60e92af1da323eb3ec2820 , pointer ), case , value )
    With pointer selected. Select Insert literal string or number, type in the cell reference in the data source (A2), and click the Apply button. SWITCH ( datasource_variable_name2,"DS1", DATASOURCE( b9d641343b60e92af1da323eb3ec2820, "A2" ) , case , value )
    With case selected. Select Insert literal string or number, type in DS2, and click the Apply button. SWITCH ( datasource_variable_name2, "DS1", DATASOURCE( b9d641343b60e92af1da323eb3ec2820, "A2" ) , "DS2", value )
    With value selected. Select Insert function, Data Manipulation, DATASOURCE. SWITCH ( datasource_variable_name2,  "DS1", DATASOURCE(b9d641343b60e92af1da323eb3ec2820, "A2" ) , "DS2", DATASOURCE( datasource_id , pointer ) case , value )
    With datasource_id selected. Select Insert literal string or number, paste in the datasource id for DS2, and click the Apply button. SWITCH ( datasource_variable_name2, "DS1", DATASOURCE( b9d641343b60e92af1da323eb3ec2820, "A2" ) , "DS2", DATASOURCE( 30adf78dfe69821cd78e45067e453230, pointer ) case , value )
    With pointer selected. Select Insert literal string or number, type in the cell reference in the data source (A2) and click the Apply button. SWITCH ( datasource_variable_name2, "DS1", DATASOURCE( b9d641343b60e92af1da323eb3ec2820, "A2" ) , "DS2", DATASOURCE( 30adf78dfe69821cd78e45067e453230, "A2") case , value )

Feedback and Knowledge Base