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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / How to pivot a single-...
Power Apps
Unanswered

How to pivot a single-record Collection?

(0) ShareShare
ReportReport
Posted on by 1,855

I have a single-record Collection. I want to display this record in a Gallery with all values shown.

 

Example:

- Collection:

 

 

ClearCollect(colTest,
 {
 id: 1, text: "test", userName: "Guy"
 }
)

 

 

 - Pivot pseudo-code:

 

 

ForEveryColumn in colTest,
 Collect(colTest2,
 {
 columnName: ThisRecord.?,
 columnValue: ThisRecord.?
 }
 )
)

 

 

Then in the Gallery:

- Items property: colTest2

- Labels set to: columnName and columnValue

 

Ideas on how to do this? I want to basically take a record in a Collection and turn it to another Collection of key-value pairs.

Categories:
I have the same question (0)
  • SanmeshG Profile Picture
    1,947 Moderator on at

    Hi @seadude  ,

     

    Please see if the below article helps. 

     

    http://powerappsguide.com/blog/post/transpose-convert-rows-to-columns

     

    Thanks!

  • timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    Hi @seadude 

    I assume the column names in your collection are dynamic. Therefore, the approach I would take is to convert the collection to JSON. You can then use string manipulation functions on the raw JSON to extract the key/value pairs.

    In the formula beneath, I build a temp collection to simplify the parsing but I'm sure you could adapt this if you prefer not to have that.

     

    ClearCollect(
     colTest,
     {
     id: 1,
     text: "test",
     userName: "Guy"
     }
    );
    Set(
     varJSON,
     JSON(colTest)
    );
    ClearCollect(
     colTemp,
     ForAll(
     Split(
     Match(
     varJSON,
     "\[\{(?<Result>.*)\}\]"
     ).Result,
     ","
     ),
     {columnName:First(Split(Value, ":")),
     columnValue:Last(Split(Value, ":"))
     } 
     )
    );
    ClearCollect(
     colTest2,
     ForAll(colTemp, {
     columnName:Substitute(columnName.Value,"""",""), 
     columnValue:Substitute(columnValue.Value, """","")}
     )
    )

     

    timl_0-1691313036862.png

     

  • seadude Profile Picture
    1,855 on at

    Hi @timl !!

     

     Man! We used to chat a LOT on here! haahh! Nice. Thanks for hollering!

     

    This is a very sophisticated suggestion! Wow! I hadn't thought about parsing JSON within PowerApps like this!

     

    RE: "I assume the column names in your collection are dynamic"

    - The column names will be the same each time

    - Just a single record collection that is being "collected into" throughout user experience

        - Use Case

            - A blank Collection is created `OnStart` of the application using `FirstN(datasource, 1)` that is subsequently `ClearCollect(colNewSurvey)`'d then `Clear(colNewSurvey)`'d

            - As the user selects values from Dropdown/Comboboxs, and enters data into Textbox Controls, they are Collected into a single record in `colNewSurvey`

            - The goal was to take this single record and transpose it to a key-value Collection that I could visualize in a single Gallery for final review before submitting `colNewSurvey`.

            - Currently on the `scrReview` Screen, I have a bunch of Label Controls set to things line `First(colNewSurvey).Column1`, `First(colNewSurvey).Column2`, etc.

            - This adds a bunch of (what I deem) unnecessary Controls to the app.

     

    I'll study your suggestion and see how it can be applied to static columns.

     

    THank yoU!

  • timl Profile Picture
    36,383 Super User 2025 Season 2 on at

    Hi @seadude 

    Just following up on this. Did you get anywhere with the above?

    On the basis that the column names are always the same, the alternative would be to hardcode the column names like so. Perhaps that might be an easier solution?

     

    Table(
     {columnName: "id", columnValue:Text(First(colTest).id)},
     {columnName: "text", columnValue:First(colTest).text},
     {columnName: "username", columnValue:First(colTest).userName}
    )

     

    timl_0-1692908782642.png

     

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 796 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 327 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard