03-30-2023 8:22 AM - edited 04-14-2023 8:11 AM
This post is part of the SAP Build Community Challenge (April 2023)
This week’s challenge involves formulas – a key feature of SAP Build Apps. Formulas are used in bindings of components, and enable you to manipulate data before it is displayed in a component or before it is sent to a data source.
Formulas are created in the formula editor, which provides some tools for making writing formulas easier:
Here are some learning materials about formulas:
We will give you an app that looks like this (I like cats).
To set up the challenge, do the following:
You should now have the skeleton project.
Inside the app, we have already created a page variable called StartValue that contains the starting data that we want you to transform.
When you are ready, on the UI Canvas, select the Transform button, open the logic canvas, then select the Set page variable flow function, and finally go to set the formula for Assigned Value on the right (which currently returns an empty list).
This is what you need to do:
Your screenshot should look something like this but without the blur (I need to see the names and averages) and with your name:
Good luck ... and have fun!!
You have to do 3 things in the formula (aggregate/group, sort, round), so find a function that does each one. Use the wonderful editor features that document the available functions.
For example, for aggregating, go to the List area, and then find a function that aggregates (in this case, GROUP). You'll see all the documentation for it on the right, plus a little playground inside the documentation for testing it. Pretty cool!
04-10-2023 4:51 PM
Hi @Dan_Wroblewski ,
Very Interesting Challenge great to learn the formulae features and the movie name is Madagascar .
Thanks,
Vijay
04-11-2023 5:16 AM
04-11-2023 11:30 AM
On to the second one now - https://groups.community.sap.com/t5/sap-builders-discussions/sap-build-challenge-week-2-ui-design/td...
04-11-2023 11:02 AM
Thanks for the challenge Dan,
Better Late than never !!
Here is the screenshot of the App and of course the Bonus, the names are from Madagascar movie
04-11-2023 11:11 AM
04-11-2023 12:22 PM
Hi Dan ,
Thanks for the challenge. Here is the screenshot and the movie is Madagascar.
Had fun learning about formulas!
04-11-2023 12:22 PM - edited 04-11-2023 12:23 PM
Hi Dan,
Thank you for the challenge. A bit tricky and interesting though 🙂
Here's my screenshot for the challenge and movie is Madagascar.
04-11-2023 12:35 PM
04-11-2023 5:01 PM
Hello Daniel,
Great idea to create these challenges.
It really forced me to study the docs and research how to use the functions used.
If it's not too much to ask, feel free to create new formula challenges (besides, of course, the others to come)
Thank you.
Best regards from Brazil.
04-13-2023 7:20 AM
04-12-2023 11:32 AM
04-13-2023 8:15 AM
04-12-2023 11:59 AM
My first time trying anything with Build Apps 😞 I couldn't get the numbers! , hence the sad smiley in the image. Anyway i can get some help on this?
Also the Movie is Madagascar ! Have to rewatch now
04-13-2023 8:17 AM
04-17-2023 6:21 AM
I had used this formula for the grouping -
GROUP(pageVars.StartValue, item.name, {name:key,actors:items})
and sorting then
SORT_BY_KEY((GROUP(pageVars.StartValue,item.name,{name:key,actors:items})),"name","asc")
04-17-2023 6:37 AM
Great ... you've grouped the data but you haven't created a single average. So instead of "actors : items" (which just creates the same list of amounts, you want a field called "average" that is equal to a number that is the average of all those items.
Luckily, you have all the items to average -- in the items object -- but you have to use the functions available to take all that data and turn it into a single number. Obviously, AVERAGE will be involved somehow, and in order to use AVERAGE you need a list of values. Consider using PLUCK to get that list from items.
04-21-2023 1:10 PM
I tried to concat the average from the item . Not sure where I am going wrong 😞
SORT_BY_KEY((GROUP(pageVars.StartValue,item.name +" "+ AVERAGE(PLUCK(item,"amount")),{name:key,average:items})),"name","asc")
04-25-2023 12:22 PM
SORT_BY_KEY((GROUP(pageVars.StartValue,item.name +" "+ AVERAGE(PLUCK(item,"amount")),{name:key,average:items})),"name","asc")
You have to Group the items, so you need something like this:
GROUP(pageVars.StartValue, item.name, {Some object})
This creates a list with one object per group (shown as pseudocode above as "Some object", but what do you want that object to be?
You want that object to have the name of the group and then an average, something like this:
{ "name" : "Marty", "average" : 12.2}
The first part you pretty much have, so it is like this:
{name: key, average: 10.11}
But of course you can't hardcode the value, you have to calculate it from the "items" list you get as an object as part of the GROUP function. In order to use the AVERAGE function, you need a simple list of numbers, so you need to convert the "items" object into the simple list, and this you use the PLUCK function.
So in the end you get:
GROUP(pageVars.StartValue, item.name, {name: key, average: ROUND(AVERAGE(PLUCK(items,"amount")), 0) })
I added a ROUND function – part of requirement – which takes an extra parameter 0 to indicate to round it to nearest whole number.
The only thing left is to sort it, which you have already started with above with the SORT_BY_KEY function.
04-25-2023 1:37 PM - edited 04-26-2023 4:28 AM
Thank you for virtually solving this for me and helping me understand where I was going wrong. I did try to add this part - AVERAGE(PLUCK(item,"amount")) with a value to "average" but did not consider items as the object to be used ! Thank you
04-12-2023 2:38 PM
04-13-2023 8:28 AM
04-13-2023 11:31 AM
04-13-2023 1:29 PM
Hi @Dan_Wroblewski ,
Thanks for the challenge, i managed to erase StartValue data at first and spent some long minutes wondering what kind of magic was bringing data in the app... and then i reimported everything.
The Movie name is Madagascar!
04-13-2023 4:01 PM
04-14-2023 8:09 AM
04-13-2023 4:06 PM
04-14-2023 8:08 AM
04-13-2023 4:11 PM
04-14-2023 12:48 AM
04-14-2023 3:15 PM
04-15-2023 6:42 PM
04-14-2023 9:53 PM
You ruined my Friday...
Personally, I prefer Skipper, Kowalski (a friend of Wroblewski?), Rico and Private 🐧
04-15-2023 6:11 PM
04-17-2023 5:21 PM
I am joining a little late to the party.. Nevertheless, here is my entry for this challenge.
Movie: Madagascar - I like to move it, move it!!
Looking forward to crack the others too..
-Sharadha
04-18-2023 6:49 AM
04-18-2023 12:40 AM
Hello Dan
I get the below error when I try to import the project on my AppGyver platform. Is the project only compatible with SAP build?
Thanks for your time
Regards
Advit
04-18-2023 6:43 AM
I believe you can export from SAP Build and import to AppGyver community edition.
But you can quickly sign up for the sandbox system to do the challenges: https://groups.community.sap.com/t5/sap-builders-blog-posts/announcing-the-sap-build-apps-sandbox/ba... ... let me know if that works for you
04-19-2023 9:39 AM
04-25-2023 1:37 PM
04-27-2023 8:11 AM