Split Choice field values into individual rows
I will go straight to the point.
I have a SharePoint list with below fields/columns:
Lets give a try!
The below code is used to extract the choice field value from each row along with employee display name.
Clear(CollBU);
Clear(CollFormattedData);
//Loop through each item from original Data
ClearCollect(
CollBU,
AddColumns(
BusinessUnit,
"BU",
Collect(
CollFormattedData,
ForAll(
Departments,
{
Values: Value,
Employee: Employee.DisplayName
}
)
)
)
);
Clear(CollBU);:- This line clears the existing data in a collection named
CollBU. - It ensures that the collection starts fresh before adding new data.
- This line clears the existing data in a collection named
Clear(CollFormattedData);:- Similarly, this line clears the existing data in another collection named
CollFormattedData.
- Similarly, this line clears the existing data in another collection named
ClearCollect(:- The
ClearCollectfunction is used to create or update a collection. - In this case, it creates a collection named
CollBU.
- The
AddColumns(:- The
AddColumnsfunction adds new columns to theCollBUcollection. - It takes the
BusinessUnitdata source (assumed to be a SharePoint list or other data) as the base collection.
- The
"BU",:- This specifies the name of the new column to be added in
CollBU. - The new column will store formatted data related to business units.
- This specifies the name of the new column to be added in
Collect(:- The
Collectfunction creates a new collection (in this case,CollFormattedData). - It iterates through each item in the
Departmentscollection (assumed to be another collection or data source).
- The
ForAll(:- The
ForAllfunction iterates through each item in theDepartmentscollection (choice field). - For each department, it creates a record (a set of key-value pairs) with two properties:
Values: Maps to the value of the department (assumed to be a column in theDepartmentscollection).Employee: Maps to the display name of the employee (assumed to be a property of theEmployeeobject).
- The
Resulting Collections:
- After executing this code, you’ll have two collections:
CollBU: Contains the original data from theBusinessUnitdata source with an additional column named “BU.”CollFormattedData: Contains data from theDepartmentscollection with “Values” and “Employee” columns.
- After executing this code, you’ll have two collections:
We have to use CollFormattedData, it has the required formatted data as shown below:





Post a Comment