cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
opit
Helper I
Helper I

how to transform data from one type of collection to other

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

1 ACCEPTED SOLUTION

Accepted Solutions

@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.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

2 REPLIES 2
v-yutliu-msft
Community Support
Community Support

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

Community Support Team _ Phoebe Liu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@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.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (48,800)