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
ClearCollect
function is used to create or update a collection. - In this case, it creates a collection named
CollBU
.
- The
AddColumns(
:- The
AddColumns
function adds new columns to theCollBU
collection. - It takes the
BusinessUnit
data 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
Collect
function creates a new collection (in this case,CollFormattedData
). - It iterates through each item in the
Departments
collection (assumed to be another collection or data source).
- The
ForAll(
:- The
ForAll
function iterates through each item in theDepartments
collection (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 theDepartments
collection).Employee
: Maps to the display name of the employee (assumed to be a property of theEmployee
object).
- The
Resulting Collections:
- After executing this code, you’ll have two collections:
CollBU
: Contains the original data from theBusinessUnit
data source with an additional column named “BU.”CollFormattedData
: Contains data from theDepartments
collection 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