What is difference between UniqBy and GroupBy clause?

Goldi Sharma Document Coding - Level 3

What is difference between UniqBy and GroupBy clause?

1

Comments

3 comments

  • Comment author
    Joanna Payoyo Athennian DocAuto Team Document Coding - Level 3
    • Official comment

    Great question!

    Let's start with some sample data.

    Affiliations

    row: 0
    participant_profileID: 123456
    participant_fullName: Leslie Knope
    role: Officer
    title: President

    row: 1
    participant_profileID: 123456
    participant_fullName: Leslie Knope
    role: Officer
    title: Secretary

    No uniqBy or groupBy
    Example Code:

    {#affiliations | filter:'role':'Officer'}{participant_fullName} is a {title}
    {/}

    Example Result:

    Leslie Knope is a President
    Leslie Knope is a Secretary

    In this case, it's not presented nicely but it does contain all of the data.

    Using uniqBy code:

    {#affiliations | filter:'role':'Officer' | uniqBy:'participant_profileID'}{participant_fullName} is a {title}
    {/}

    Example uniqBy Data:

    Using uniqBy will change the data to only capture one instance of that person, in this case we will be left with only one instance of Leslie Knope.

    Affiliations with uniqBy:participant_profileID

    row: 0
    participant_profileID: 123456
    participant_fullName: Leslie Knope
    role: Officer
    title: President

    Using the uniqBy code above, the result will be:

    Leslie Knope is a President.

    So you can see here that this data is inaccurately portraying that Leslie Knope is only a President. uniqBy will not allow us to access the other title as it only finds one instance.

    Using groupBy code:

    {#affiliations | filter:'role':'Officer' | groupBy:'participant_profileID'}{group | grab:1:'participant_fullName'} is a {group | toSentence:'title'}
    {/}

    Example groupBy Data:

    Using groupBy will change the data to create a subcollection within the original collection that is grouped by the shared variable, in this case we're using participant_profileID. In the below example, both rows are included under group:0 because they share the same participant_profileID.

    Affiliations with groupBy:'participant_profileID'

    group: 0
    row: 0
    participant_profileID: 123456
    participant_fullName: Leslie Knope
    role: Officer
    title: President

    row: 1
    participant_profileID: 123456
    participant_fullName: Leslie Knope
    role: Officer
    title: Secretary

    Using the groupBy code above, the result will be:

    Leslie Knope is a President and Secretary

    groupBy allows us access to all of the information but groups the information together with the shared variable (in this case participant_profileID)

  • Comment author
    Goldi Sharma Document Coding - Level 3

    Andy Chiang @... @...

    0
  • Comment author
    Goldi Sharma Document Coding - Level 3

    Thanks Joanna, got it. Great explaination.

    0

Please sign in to leave a comment.