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 Apps / how to transform data ...
Power Apps
Answered

how to transform data from one type of collection to other

(0) ShareShare
ReportReport
Posted on by 162

Hi,

Could somebody give me some ideas for below problem?

I have collection like below:

 

ClearCollect(_testGamyba;
 {Id: 1; OperacijosId: 1; Tipas: "Fasadas"; Reiksme: 2};
 {Id: 2; OperacijosId: 1; Tipas: "Korpusas"; Reiksme: 0};
 {Id: 3; OperacijosId: 2; Tipas: "Fasadas"; Reiksme: 1};
 {Id: 4; OperacijosId: 2; Tipas: "Korpusas"; Reiksme: 0};
 {Id: 5; OperacijosId: 3; Tipas: "Fasadas"; Reiksme: 0};
 {Id: 6; OperacijosId: 3; Tipas: "Korpusas"; Reiksme: 2};
 {Id: 7; OperacijosId: 4; Tipas: "Fasadas"; Reiksme: 0};
 {Id: 8; OperacijosId: 4; Tipas: "Korpusas"; Reiksme: 2}
)

And I would like to transform it to following on screen loading:

 

ClearCollect(_testGamyba;
 {Id: 1; OperacijosId: 1; Fasadas: 2; Korpusas: 0};
 {Id: 2; OperacijosId: 2; Fasadas: 1; Korpusas: 0};
 {Id: 3; OperacijosId: 3; Fasadas: 0; Korpusas: 2};
 {Id: 4; OperacijosId: 4; Fasadas: 0; Korpusas: 2}
)

The purpose of that is to transform data to be available for form with checkboxes:

Capture.PNG

Categories:
  • v-yutliu-msft Profile Picture
    Microsoft Employee on at

    Hi @opit,

    Do you want to transfer collection1 to the format of collection2?

    I’ve made a similar test as follows:

    Create four buttons

    Set button1’s OnSelect:

    ClearCollect(_testGamyba,{Id: 1,OperacijosId:1,Tipas: "Fasadas",Reiksme: 2},
        {Id: 2,OperacijosId: 1,Tipas: "Korpusas", Reiksme: 0},
        {Id: 3, OperacijosId: 2,Tipas: "Fasadas",Reiksme: 1},
        {Id: 4,OperacijosId: 2,Tipas: "Korpusas",Reiksme: 0},
        {Id: 5,OperacijosId: 3,Tipas: "Fasadas",Reiksme: 0},
        {Id: 6,OperacijosId: 3,Tipas: "Korpusas", Reiksme: 2},
        {Id: 7,OperacijosId: 4,Tipas: "Fasadas",Reiksme: 0},
        {Id: 8, OperacijosId: 4,Tipas: "Korpusas",Reiksme: 2}
    )                                                                                                                                     
     /////create collection1

    4221.jpg

     

    Set button2’s OnSelect:

    ClearCollect(_testGamyba1,AddColumns(_testGamyba,
    "Fasadas",If(Tipas="Fasadas",Reiksme,Blank()),
    "Korpusas",If(Tipas="Korpusas",Reiksme,Blank())
    )
    )                    
            ////update value to Fasadas、Korpusas column

    4222.jpg

     

    Set button3’s OnSelect:

    ClearCollect(_testGamyba2,GroupBy(_testGamyba1,"OperacijosId","old"))       
                                                               /////group according to OperacijosId column

    4223.jpg

     

    4224.jpg

     

    Set button4’s OnSelect:

    ClearCollect(_testGamyba3,AddColumns(_testGamyba2,
    "id",OperacijosId,
    "Fasadas",Concat(Filter(old,!IsBlank(Fasadas)),Fasadas&""),
    "Korpusas",Concat(Filter(old,!IsBlank(Korpusas)),Korpusas&"")
    )
    )     
    /////combine two fields’ value

    4226.png

     

    After these practices, collection1 will be transferred to the format of collection2.

     

     

     

     

     

    Best regards,

    Community Support Team _ Phoebe Liu

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @opit 

    I believe that @v-yutliu-msft has the right info for you.  I had worked this out as well, so thought I would share also.

     

    @v-yutliu-msft - didn't see your posting until after I had already took a crack at this...

     

    Here is what I had come up with for your OnVisible action (you did mention you wanted this to happen on screen load).

    Clear(_testGamybaTransform);
    
    ForAll(
     AddColumns(
     GroupBy(
     AddColumns(_testGamyba, "Fas", If(Tipas="Fasadas", Reiksme,0), "Kor", If(Tipas="Korpusas", Reiksme,0)),
     "OperacijosId", "Items"),
     "Fasadas", Sum(Items, Fas),
     "Korpusas", Sum(Items, Kor)
     ),
     Collect(_testGamybaTransform,
     {Id: CountRows(_testGamybaTransform)+1,
     OperacijosId: OperacijosId,
     Fasadas: Fasadas,
     Korpusas: Korpusas
     }
     )
    )
    

    Pretty much the same formula, but combined into one.  The only difference was with the Id.  I wasn't sure if your OperacijosId would always be the same as your "Id" that you wanted, so, my formula calculates the sequential Id as it builds the collection.

     

    I hope the two formulas provided here are helpful for you.

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 Apps

#1
11manish Profile Picture

11manish 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 283

#3
Mohsin Ali Profile Picture

Mohsin Ali 221

Last 30 days Overall leaderboard