cancel
Showing results for 
Search instead for 
Did you mean: 
Get Started Discussions
Start your journey with Databricks by joining discussions on getting started guides, tutorials, and introductory topics. Connect with beginners and experts alike to kickstart your Databricks experience.
cancel
Showing results for 
Search instead for 
Did you mean: 

Is there a way to iterate over a combination of parameters using a "for each" task?

sys08001
New Contributor II

Hi,

I have a notebook with two input widgets set up ("current_month" and "current_year") that the notebook grabs values from and uses for processing. I want to be able to provide a list of input values in the "for each" task where each value is actually a value pair corresponding to the widget values e.g. ("January", "2023") and then specify that I want the notebook task to be iterated over using the paired values. I have only been able to find instructions for iterating over values corresponding to a single parameter (e.g. you can provide an input list ["January", "February", etc.] in the for each task and then create a parameter in the notebook task of "current_month" set equal to "{{input}}") and was wondering if what I'm trying to accomplish is possible? 

1 ACCEPTED SOLUTION

Accepted Solutions

ashraf1395
Honored Contributor

Hi there @sys08001 , yup it is possible 

you can pass the input values for the for_each task in json format 
Somewhat like this

[
  {
    "tableName": "product_2",
    "id": "1",
    "names": "John Doe",
    "created_at": "2025-02-22T10:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "2",
    "names": "Jane Smith",
    "created_at": "2025-02-22T11:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "3",
    "names": "Alice Johnson",
    "created_at": "2025-02-22T12:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "1",
    "names": "John Doe",
    "created_at": "2025-02-22T10:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "2",
    "names": "Jane Smith",
    "created_at": "2025-02-22T11:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "3",
    "names": "Alice Johnson",
    "created_at": "2025-02-22T12:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "1",
    "names": "John Doe",
    "created_at": "2025-02-22T10:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "2",
    "names": "Jane Smith",
    "created_at": "2025-02-22T11:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "3",
    "names": "Alice Johnson",
    "created_at": "2025-02-22T12:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "1",
    "names": "John Doe",
    "created_at": "2025-02-22T10:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "2",
    "names": "Jane Smith",
    "created_at": "2025-02-22T11:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "3",
    "names": "Alice Johnson",
    "created_at": "2025-02-22T12:00:00.000Z"
  }
]

and then can in the each task you can use {{input.field_name}}

 

for you usecase , you can create a json input like this 
[ { "month": "January", "year" : "2025" }, ... ]
and then in the each task you can use input.month or input.year to call it, 
you can create two separate parameters for calling them or can have them in a single parameter as well  
by referencing them like this

( {{input.month}} , {{input.year}} )

View solution in original post

1 REPLY 1

ashraf1395
Honored Contributor

Hi there @sys08001 , yup it is possible 

you can pass the input values for the for_each task in json format 
Somewhat like this

[
  {
    "tableName": "product_2",
    "id": "1",
    "names": "John Doe",
    "created_at": "2025-02-22T10:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "2",
    "names": "Jane Smith",
    "created_at": "2025-02-22T11:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "3",
    "names": "Alice Johnson",
    "created_at": "2025-02-22T12:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "1",
    "names": "John Doe",
    "created_at": "2025-02-22T10:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "2",
    "names": "Jane Smith",
    "created_at": "2025-02-22T11:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "3",
    "names": "Alice Johnson",
    "created_at": "2025-02-22T12:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "1",
    "names": "John Doe",
    "created_at": "2025-02-22T10:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "2",
    "names": "Jane Smith",
    "created_at": "2025-02-22T11:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "3",
    "names": "Alice Johnson",
    "created_at": "2025-02-22T12:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "1",
    "names": "John Doe",
    "created_at": "2025-02-22T10:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "2",
    "names": "Jane Smith",
    "created_at": "2025-02-22T11:00:00.000Z"
  },
  {
    "tableName": "product_2",
    "id": "3",
    "names": "Alice Johnson",
    "created_at": "2025-02-22T12:00:00.000Z"
  }
]

and then can in the each task you can use {{input.field_name}}

 

for you usecase , you can create a json input like this 
[ { "month": "January", "year" : "2025" }, ... ]
and then in the each task you can use input.month or input.year to call it, 
you can create two separate parameters for calling them or can have them in a single parameter as well  
by referencing them like this

( {{input.month}} , {{input.year}} )