web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / create a single-valued...
Power Automate
Unanswered

create a single-valued list from a duplicate list

(0) ShareShare
ReportReport
Posted on by 120

what technique can i use to create a list with unique values from a list with duplicates, i'm trying to run javascript but i can't, any ideas?

  • Henrik_M Profile Picture
    2,021 Super User 2024 Season 1 on at

    Henrik_M_0-1641478285433.png

     

  • douglasabreu Profile Picture
    120 on at

    okay, looks like a good way.

    I have a list with duplicates and I want to actually count the duplicates and sort the list.

     

    exemple - If I have:

    Brazil
    japan
    India
    Philippines
    japan
    Peru
    Brazil
    India
    USA
    India
    Qatar

     

    so i need:

    3 | India
    2 | Brazil
    2 | japan
    1 | Qatar
    1 | USA
    1 | Philippines
    1 | Peru

     

    do you see any way to process this inside the PAD?

     

    this online tool does this:
    https://www.somacon.com/p568.php

  • Henrik_M Profile Picture
    2,021 Super User 2024 Season 1 on at

    Wouldn't surprise me if there's a smarter way to do this, but do have a look. Paste this into a blank desktop flow:

     

    SET Text TO $'''Brazil
    japan
    India
    Philippines
    japan
    Peru
    Brazil
    India
    USA
    India
    Qatar'''
    Text.SplitText.Split Text: Text StandardDelimiter: Text.StandardDelimiter.NewLine DelimiterTimes: 1 Result=> TextList_Countries
    Text.SplitText.Split Text: Text StandardDelimiter: Text.StandardDelimiter.NewLine DelimiterTimes: 1 Result=> TextList_Unique
    Variables.RemoveDuplicateItemsFromList List: TextList_Unique IgnoreCase: False NewList=> TextList_Unique
    LOOP FOREACH Current_Unique IN TextList_Unique
     Variables.ConvertJsonToCustomObject Json: $'''{ \"Count\": 0, \"Country\": \"%Current_Unique%\" }''' CustomObject=> JsonAsCustomObject
     Variables.AddItemToList Item: JsonAsCustomObject List: List_Country_With_Counts NewList=> List_Country_With_Counts
    END
    LOOP FOREACH Current_Country IN TextList_Countries
     LOOP LoopIndex FROM 0 TO List_Country_With_Counts.Count - 1 STEP 1
     IF Current_Country = List_Country_With_Counts[LoopIndex]['Country'] THEN
     SET List_Country_With_Counts[LoopIndex]['Count'] TO List_Country_With_Counts[LoopIndex]['Count'] + 1
     EXIT LOOP
     END
     END
    END
    Variables.SortList.SortListByProperty List: List_Country_With_Counts Property1: $'''Count''' SortDirection1: Variables.SortDirection.Descending SortDirection2: Variables.SortDirection.Ascending SortDirection3: Variables.SortDirection.Ascending SortedList=> List_Country_With_Counts
    LOOP FOREACH Current_Sorted_Country IN List_Country_With_Counts
     Variables.AddItemToList Item: $'''%Current_Sorted_Country['Count']% | %Current_Sorted_Country['Country']%''' List: Final_List NewList=> Final_List
    END
  • MichaelAnnis Profile Picture
    5,727 Moderator on at

    Henrik's way is a great PAD-only option.

     

    I would combine PAD and VBA to solve this faster.  Create a macro workbook with the following macro.  Have PAD write the list to A1, then run this macro:

    Sub CountList()
    '
    ' CountList Macro
    ' Copy List Remove Duplicates Count List
    '

    '
    Columns("A:A").Select
    Selection.Copy
    Columns("D:D").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Dim LR As Long 'Last Row
    Range("D1").Select
    Selection.End(xlDown).Select
    LR = Selection.Row
    Application.CutCopyMode = False
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add2 Key:=Range("D1:D" & LR) _
    , SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
    .SetRange Range("D1:D" & LR)
    .Header = xlGuess
    .MatchCase = False
    .Orientation = xlTopToBottom
    .SortMethod = xlPinYin
    .Apply
    End With
    ActiveSheet.Range("$D$1:$D$" & LR).RemoveDuplicates Columns:=1, Header:=xlNo
    Range("D1").Select
    Selection.End(xlDown).Select
    LR = Selection.Row 'now it is the last row after removing duplicates
    Range("C1").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=COUNTIF(C1,RC[1])"
    Range("C1").Select
    Selection.AutoFill Destination:=Range("C1:C" & LR)
    Range("C1:C" & LR).Select
    Columns("C:C").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Columns("A:B").Select
    Application.CutCopyMode = False
    Selection.Delete Shift:=xlToLeft
    End Sub

  • douglasabreu Profile Picture
    120 on at

    Good solutions.

     

    I did work using groups of collections. Initially I removed the duplicates from a list with duplicates, and with the new list I went one by one and then along the way I used parse to find the repetitions within the list with the duplicates and generated a new list with the matches, I then I count the number of repetitions of this list macth and enter use the if to know if the amount is more or less to my interest, and as I allocate the item in a new collection, that solved my problem, I created 5 groups of collections. from 1 to 10, from 11 to 20, from 21 to 30...

     

    It's not exactly an ordering, but as the flow only uses native actions, I preferred to think of something less programmatic.

     

    Thanks to friends!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 426

#2
11manish Profile Picture

11manish 345 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 308

Last 30 days Overall leaderboard