Friday, September 18, 2026

Power Automate Desktop: Find One-to-Many Values Between Two Columns

Power Automate Desktop: Find One-to-Many Values Between Two Columns

The Problem

You have a table with two columns, A and B. You want to find every A value that is linked to more than one different B value.

✅ One-to-many❌ Not one-to-many
Apple → Red, GreenBanana → Yellow, Yellow (same value repeated)
Date → Brown (only one value)

No scripts needed. Only built-in Power Automate Desktop (PAD) actions.


Sample Data

AB
AppleRed
AppleGreen
BananaYellow
BananaYellow
CherryRed
CherryBlack
DateBrown
FigPurple
FigGreen
GrapePurple

How It Works (3 Simple Steps)

StepWhat happens
1Get the unique list of A values
2For each A value, collect its unique B values
3If there are more than 1 B values → add it to the result

Variables Used

VariableTypePurpose
InputDTData tableSource data (A, B)
DistinctAValuesListUnique A values
OneToManyResultsData tableFinal result
CurrentRowData rowRow being read (Step 1)
CurrentAValueTextA value being checked
BValuesForThisAListUnique B values for current A
DataRowData rowRow being read (Step 2)
BValuesTextTextB values joined as "Red, Green"

Build the Flow

Step 1 — Create the input table

Variables → Create new data table → add columns A and B → enter the sample rows → name it InputDT.

In real projects, use Excel → Read from Excel worksheet instead.

Step 2 — Get unique A values

ActionSetting
Create new listName: DistinctAValues
For eachLoop InputDT, item: CurrentRow
IfDistinctAValues Does not contain CurrentRow['A']
Add item to listAdd CurrentRow['A'] to DistinctAValues

Result: Apple, Banana, Cherry, Date, Fig, Grape

Step 3 — Create the result table

Variables → Create new data table → columns A Value and Matching B Values → name it OneToManyResults.

💡 The visual builder adds one empty row by default. Delete it in the builder (or add Clear data table right after) so your result doesn't start with a blank line.

Step 4 — Check each A value

ActionSetting
For eachLoop DistinctAValues, item: CurrentAValue
Create new listName: BValuesForThisA (inside the loop, so it resets each time)
For eachLoop InputDT, item: DataRow
IfDataRow['A'] Equal to CurrentAValue
IfBValuesForThisA Does not contain DataRow['B']
Add item to listAdd DataRow['B'] to BValuesForThisA
IfBValuesForThisA.Count Greater than 1
Join textJoin BValuesForThisA with ,  → BValuesText
Insert row into data tableAdd [CurrentAValue, BValuesText] to OneToManyResults

Step 5 — Show the result

Message boxes → Display message → show OneToManyResults.


Output

A ValueMatching B Values
AppleRed, Green
CherryRed, Black
FigPurple, Green

Banana, Date and Grape are skipped. ✔️


Quick Tips

TipWhy
Create BValuesForThisA inside the loopOtherwise old values carry over
Use %CurrentRow[0]% if no headersColumn index starts at 0
Good for small/medium tablesNested loops slow down on thousands of rows

Complete Code

Copy the code below and paste it directly into the PAD designer (Ctrl + V).

Variables.CreateNewDatatable InputTable: { ^['A', 'B'], [$'''Apple''', $'''Red'''], [$'''Apple''', $'''Green'''], [$'''Banana''', $'''Yellow'''], [$'''Banana''', $'''Yellow'''], [$'''Cherry''', $'''Red'''], [$'''Cherry''', $'''Black'''], [$'''Date''', $'''Brown'''], [$'''Fig''', $'''Purple'''], [$'''Fig''', $'''Green'''], [$'''Grape''', $'''Purple'''] } DataTable=> InputDT
Variables.CreateNewList List=> DistinctAValues
LOOP FOREACH CurrentRow IN InputDT
    IF NotContains(DistinctAValues, CurrentRow['A'], False) THEN
        Variables.AddItemToList Item: CurrentRow['A'] List: DistinctAValues
    END
END
Variables.CreateNewDatatable InputTable: { ^['A Value', 'Matching B Values'], [$'''''', $''''''] } DataTable=> OneToManyResults
LOOP FOREACH CurrentAValue IN DistinctAValues
    Variables.CreateNewList List=> BValuesForThisA
    LOOP FOREACH DataRow IN InputDT
        IF DataRow['A'] = CurrentAValue THEN
            IF NotContains(BValuesForThisA, DataRow['B'], False) THEN
                Variables.AddItemToList Item: DataRow['B'] List: BValuesForThisA
            END
        END
    END
    IF BValuesForThisA.Count > 1 THEN
        Text.JoinText.JoinWithCustomDelimiter List: BValuesForThisA CustomDelimiter: $''', ''' Result=> BValuesText
        Variables.AddRowToDataTable.AppendRowToDataTable DataTable: OneToManyResults RowToAdd: [CurrentAValue, BValuesText]
    END
END
Display.ShowMessageDialog.ShowMessage Title: $'''One-to-Many Results''' Message: OneToManyResults Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: False ButtonPressed=> ButtonPressed







References

No comments:

Post a Comment

Featured Post

Power Automate Desktop: Find One-to-Many Values Between Two Columns

Power Automate Desktop: Find One-to-Many Values Between Two Columns The Problem You have a table with two columns, A and B . You want to fi...

Popular posts