SAP Builders Discussions
Join the discussion -- ask questions and discuss how you and fellow SAP Builders are using SAP Build, SAP Build Apps, SAP Build Process Automation, and SAP Build Work Zone.
cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Build Challenge – Week 1 – Formulas

thecodester
Developer Advocate
Developer Advocate

This post is part of the SAP Build Community Challenge (April 2023)

dan_wroblewski_0-1680162815071.png

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.

dan_wroblewski_0-1680162183899.png

Formulas are created in the formula editor, which provides some tools for making writing formulas easier:

  • It has a list of functions, which can be added to the formula with a click.
  • It has documentation on each function, plus examples.
  • It has a live testing of functions so you can be certain how they work.
  • It checks the syntax of the formula.
  • It shows an expected sample result of the function.
  • It checks the resulting data type against the data type expected by the component or flow function using the formula.

Here are some learning materials about formulas:

 

Setup

We will give you an app that looks like this (I like cats).

dan_wroblewski_0-1680161844555.png

To set up the challenge, do the following:

  1. Download the skeleton project called Challenge - Formulas.zip.gpg.
  2. Create a new SAP Build Apps project in your tenant or the sandbox.
  3. Import the downloaded file into your new project by selecting History > Replace in the top-right corner, and then selecting the downloaded project. 

dan_wroblewski_1-1680205193965.png

You should now have the skeleton project.

dan_wroblewski_0-1680205123196.png

Inside the app, we have already created a page variable called StartValue that contains the starting data that we want you to transform. 

 

The Challenge

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

dan_wroblewski_3-1680160487847.png

This is what you need to do:

  1. Write a formula that replaces the empty list for the assigned value and that does the following:
    • Aggregates the data from StartValue so that in EndValue each name appears only once with an average calculated from the amount fields.
    • Names should be sorted alphabetically, from A to Z
    • Averages should be rounded to the nearest integer.
  2. Launch your app.
  3. Click the Transform button (which will display 4 names and an average for each), and then type your name in the input field.
  4. Take a screenshot and post it to THIS discussion.
    • BONUS: Add to your entry the movie from where the 4 names in the results are taken.

Your screenshot should look something like this but without the blur (I need to see the names and averages) and with your name:

dan_wroblewski_1-1680162021890.png

Good luck ... and have fun!!

 

Hint

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! 

 dan_wroblewski_0-1680588176659.png




--------------
See all my blogs and connect with me on Twitter / LinkedIn
174 REPLIES 174

VijayCR
Active Contributor

Hi @thecodester  ,

Very Interesting Challenge great to learn the formulae features and the movie name is Madagascar .

Build challange 1.PNG

Thanks,

Vijay

Chetan_Jadhav
Discoverer

Hi Dan,
Completed First Challenge. It was Great.
Movie Madagascar.

Chetan_Jadhav_0-1681186492919.png

 

saranraj_9021
Explorer

Thanks for the challenge Dan, 

Better Late than never !! 

Screenshot_20230411_152932_com.sap.appgyver.preview.release.jpg

 

Here is the screenshot of the App and of course the Bonus, the names are from Madagascar movie 

Not late at all ... you have to end of month to do any and all the challenges 😺




--------------
See all my blogs and connect with me on Twitter / LinkedIn

SubaR
Explorer

Hi Dan ,

Thanks for the challenge. Here is the screenshot and the movie is Madagascar.

Had fun learning about formulas!

SubaR_0-1681212086081.png

 

Kashish_Rajpal
Explorer

Hi Dan,

Thank you for the challenge. A bit tricky and interesting though 🙂
Here's my screenshot for the challenge and movie is Madagascar.

Kashish_Rajpal_0-1681212041222.png

 

0 Kudos

Great! 😺

We didn't want it to be too easy




--------------
See all my blogs and connect with me on Twitter / LinkedIn

LeandroRibeiro
Participant

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.

Screenshot_20230411-124437~2.png

 

0 Kudos

Weekly challenges, including or especially for formulas, is an interesting and fun idea. Thanks for participating.




--------------
See all my blogs and connect with me on Twitter / LinkedIn

nishantbansal91
Active Contributor

Sorry for late @thecodester 

This is the output

nishantbansal91_0-1681295475341.png

 

 

0 Kudos

Not late at all -- you have till May 7 for all of them 😺




--------------
See all my blogs and connect with me on Twitter / LinkedIn

PriyanjanaRoy
Associate
Associate

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 
Screenshot 2023-04-12 162819.png

0 Kudos

I didn't mean to make you sad 😐 Share your formula and we can work together. You obviously got the grouping part OK.




--------------
See all my blogs and connect with me on Twitter / LinkedIn

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")

0 Kudos

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.




--------------
See all my blogs and connect with me on Twitter / LinkedIn

PriyanjanaRoy_0-1682078954906.png

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")

0 Kudos

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.




--------------
See all my blogs and connect with me on Twitter / LinkedIn

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 

PriyanjanaRoy_0-1682479673325.png

 

 

ec1
Active Participant

Great challenge as always.

The movie is Madagascar. 

stevanic_0-1681306696888.png

S

Vishal_97
Explorer

Hi @thecodester ,

Thanks for the interesting challenge. The Movie name is Madagascar!

Screenshot 2023-04-13 125703.png

govardhansahil
Explorer

Thanks for the challenge. It is great way to learn and get familiar with the tools. Looking forward for upcoming challenges.

govardhansahil_0-1681381852562.png

Tomislav
Explorer

Hi @thecodester ,

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!

 

Tompa_0-1681388753068.png

 

former_member136915
Product and Topic Expert
Product and Topic Expert

Hello Dan,

SAP Build Challenge 1.png

Movie is Madagascar.

Inspiring SAP Build Challenge.

Thanks.

0 Kudos

Thanks for participating 😺




--------------
See all my blogs and connect with me on Twitter / LinkedIn

evra83
Explorer

Hi Dan,

Thanks for this challenge

Challenge 01 Vladimir Romero.jpeg

 

thecodester
Developer Advocate
Developer Advocate
0 Kudos

Can you show your formula?




--------------
See all my blogs and connect with me on Twitter / LinkedIn

Ranjith_Kumar
Explorer

Hi Dan, 

Thanks for the challenge . late to the trend..;)

Movie name: Madagascar

Ranjith_Kumar_1-1681398662205.png

 

PrashantJayaram
Product and Topic Expert
Product and Topic Expert

Screenshot 2023-04-13 at 4.39.06 PM.png

Hi Daniel, please see above.  And the movie is Madagascar.

HorstSchaude
Product and Topic Expert
Product and Topic Expert

SAP Build Challenge 1.jpg

Finally 😉

0 Kudos

Thanks for entering and keeping at it until it was complete 😺




--------------
See all my blogs and connect with me on Twitter / LinkedIn

Vitaliy-R
Developer Advocate
Developer Advocate

You ruined my Friday...

Screenshot 2023-04-14 at 22.48.54.png

Personally, I prefer Skipper, Kowalski (a friend of Wroblewski?), Rico and Private 🐧 

Sorry about that. Yes, I should have used the penguins, or the monkeys




--------------
See all my blogs and connect with me on Twitter / LinkedIn

Sharadha1
Active Contributor

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!! 

Screenshot 2023-04-17 at 17.17.16.png

 Looking forward to crack the others too..

 

-Sharadha

 

Not late at all ... still another 3 weeks for all the challenges ... hope you continue with the others 😺




--------------
See all my blogs and connect with me on Twitter / LinkedIn

advitramesh
Explorer

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?

advitramesh_0-1681774797806.png

Thanks for your time

Regards

Advit

 

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




--------------
See all my blogs and connect with me on Twitter / LinkedIn

rudavi
Explorer
0 Kudos

Hello Dan,

Sorry for being late,  but I discovered this challenge just yesterday

Thanks for this challenge!!

Please see the screenshot below:

C2A8707F-D026-4D18-8535-34CB537833AE.png

thecodester
Developer Advocate
Developer Advocate
0 Kudos

Thanks for joining ... but the data above is not correct ... what happened? You were supposed to use the data already inside the app 




--------------
See all my blogs and connect with me on Twitter / LinkedIn

Sorry, I was thinking about switching the data to something I liked best.