cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
opit
Level: Powered On

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
Super User
Super User

Re: how to transform data from one type of collection to other

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

2 REPLIES 2
Community Support Team
Community Support Team

Re: how to transform data from one type of collection to other

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.
Super User
Super User

Re: how to transform data from one type of collection to other

@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. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.

View solution in original post

Helpful resources

Announcements
New Ranks and Rank Icons in April

'New Ranks and Rank Icons in April

Read the announcement for more information!

Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (2,293)