cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
thomas_d
Level 8

Multi selection and count function

Hi,
I would like to create an app with the following functionalities:

The user can select the desired images. In the background is a number for each image.

 

Then you can click on "Count". Now the numbers of the selected pictures are calculated together (Sum).

Do you have a hint how to do this? Preferably without a Gallery.


Thanks for your support

 

12-03-_2019_11-15-01.jpg

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Community Support Team
Community Support Team

Re: Multi selection and count function

HI @thomas_d ,

Do you want to achieve your needs without using Gallery in your app?

 

Based on the needs that you mentioned, if you want to achieve your needs without using Gallery in your app, I think there is no simple way to achieve your needs.

 

Based on the screenshot that you mentioned, I think you have some misunderstanding on the OnStart property of the App control in PowerApps.

The OnStart property of the App control in PowerApps would be fired when you start running your app. Of course, you could consider manually fire this property via clicking "Run OnStart" option as below:1.JPG

Please consider take a try to click "Run OnStart" option of the App control manually within your app, then check if the collection is populated with values.

Please check the following GIF screenshot for more details:Test.gif

 

In addition, there is also something wrong when you referenced Media Images within your RecordsCollection. You should not wrap the image name with double quotes ("") in your RecordsCollection, you should directly reference the image name for the ImageColumn in your Collection.

Please modify your formula as below:

ClearCollect(
             RecordsCollection, 
             {ImageColumn: 'Chatbots-2', NumberColumn:1},
             {ImageColumn: '800px_COL...', NumberColumn:1},
             ...
)

Note: You may need to wrap the image name with single quote ('') in your collection.

 

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
thomas_d
Level 8

Re: Multi selection and count function

I got a solution for the second question Smiley Wink If(And(SumValue<=148);'Picture1';If(And(SumValue>=148;SumValue<=350);'Picture2';If(And(SumValue>=350);'Picture3'))) That seems to work
10 REPLIES 10
rebeccas
Level 10

Re: Multi selection and count function

Use CountIf

 

So it would be = CountIf(Gallery1.AllItems, Checkbox1.Value=true)

 

That will count all items in that gallery that have the checkbox selected as true.

 

BenFetters
Level 8

Re: Multi selection and count function

Hello,

 

My idea would be to have the OnVisible property of your screen set a variable like this:

UpdateContext({VariableName: 0 })

 

Then, for each image that you have on your screen, use the same UpdateContext to update the variable or "add" value to the variable. On the OnSelect property of your image use a formula like this: UpdateContext({VariableName: VariableName + 1 })

 

This means that the variable = what it already was and then adds one. Hopefully that makes sense. If you wanted to add a different amount based on picture that the user selects, you can simply change the 1 to a 2 or whatever you want it to be

 

Then, for you label, have it's Text prorperty set to: VariableName

If you want to hide the label so that when you select the button it will show the label you coul use a Boolean variable. I can explain that if you would like as well. 

 

I hope that helps! 

Let me know if any of that didn't make sense at all.

 

Kind regards,

Ben

 

thomas_d
Level 8

Re: Multi selection and count function

Thanks for your input. I will try this Smiley Wink

 

Do you have maybe also an idea, how the select and deselect can be done? So for example Borderthickness (value 3)  when selected, click again --> deselect Borderthickness 0. Of course, the counting should also be undone.

 

I think the whole thing is tougher than I thought. -_-

Community Support Team
Community Support Team

Re: Multi selection and count function

Hi @thomas_d ,

Could you please share more details about the data source (which contains image data and background number value) you want to use within your app?

 

Based on the needs that you mentioned, I think the Checkbox control and a Gallery could achieve your needs. I assume that you have created corresponding columns in your data source to store the image data (e.g. Image URL) and the background number value -- ImageColumn and NumberColumn.

 

I have made a test on my side, please take a try with the following workaround:7.JPG

 

8.JPG

 

9.JPG

 

10.JPG

Set the OnStart property of App (Or OnVisible property of the first screen of app) to following:

ClearCollect(
             RecordsCollection, 
             {ImageColumn: "https://images.pexels.com/photos/1308881/pexels-photo-1308881.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500", NumberColumn:1},
             {ImageColumn: "https://images.pexels.com/photos/458766/pexels-photo-458766.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500", NumberColumn:5},
             {ImageColumn: "https://images.pexels.com/photos/457702/pexels-photo-457702.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500", NumberColumn:3},
             {ImageColumn: "https://images.pexels.com/photos/74512/pexels-photo-74512.jpeg?auto=compress&cs=tinysrgb&dpr=1&w=500", NumberColumn:7}
)

Within the Gallery, add a Checkbox control (Checkbox1), a Image control and a Label control. Set the Image property of the Image control to following:

ThisItem.ImageColumn

Set the Text property of the Label control to following:

ThisItem.NumberColumn

Set the Items property of the Gallery  (Gallery1) to following:

RecordsCollection

 

Set the OnSelect property of the "Count" button to following:

Set(SumValue, Sum(Filter(Gallery1.AllItems, Checkbox1.Value = true), NumberColumn))

Set the Text property of the Sum Label control to following:

"SUM: "& SumValue

Please check attached GIF screeshot for more details:Test.gif

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
thomas_d
Level 8

Re: Multi selection and count function

Thanks a lot for your feedback. Nice Solution. Here some more information about my idea: The goal is the following, I want to create an app where the user can select different images. (Example: Pictures from Cars). Every Car has a price. It should count the prices of the selected Cars (images) in the background and display the value in one sum. The data source is not available, i.e. the images of the cars are only in the app. It actually does not need a "Gallery". Is it also possible to use the images just like this:

 

image.png

image.png

I saw it created a collection but without entries:

 

image.png

Maybe that works only with URL's and not with the pictures directly...

rebeccas
Level 10

Re: Multi selection and count function

@thomas_d 

For the Border Thickness example you would just put on the border thickness = If(Checkbox1.Value=true, 2, 5)  or whatever numbers you want to use for your thickness.

Community Support Team
Community Support Team

Re: Multi selection and count function

HI @thomas_d ,

Do you want to achieve your needs without using Gallery in your app?

 

Based on the needs that you mentioned, if you want to achieve your needs without using Gallery in your app, I think there is no simple way to achieve your needs.

 

Based on the screenshot that you mentioned, I think you have some misunderstanding on the OnStart property of the App control in PowerApps.

The OnStart property of the App control in PowerApps would be fired when you start running your app. Of course, you could consider manually fire this property via clicking "Run OnStart" option as below:1.JPG

Please consider take a try to click "Run OnStart" option of the App control manually within your app, then check if the collection is populated with values.

Please check the following GIF screenshot for more details:Test.gif

 

In addition, there is also something wrong when you referenced Media Images within your RecordsCollection. You should not wrap the image name with double quotes ("") in your RecordsCollection, you should directly reference the image name for the ImageColumn in your Collection.

Please modify your formula as below:

ClearCollect(
             RecordsCollection, 
             {ImageColumn: 'Chatbots-2', NumberColumn:1},
             {ImageColumn: '800px_COL...', NumberColumn:1},
             ...
)

Note: You may need to wrap the image name with single quote ('') in your collection.

 

Please take a try with above solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
thomas_d
Level 8

Re: Multi selection and count function

Thanks for your support. Now it works great with a gallery! I just thought without gallery it would be better, because there are more possibilities to design the look of the app.

 

But it's ok, so thanks again Smiley Wink

thomas_d
Level 8

Re: Multi selection and count function

I have another question:

If I wanted to display a picture depending on this sum, how would I do that best?

I tried the following:

 

image.png

 

So that means a Sum between 0 and 148 shows Picture 1, between 149-349 shows Picture 2 and over 350 picture 3. 

I've tried it with that if statement, the first two are working, but if the sum is over 350 it shows picture 2 and not picture 3. I think thats because the first condition matches.

 

Is it possible to use some sort of "range" in a if statement? So "if a number between 0-148, then....."