Forum Academy Marketplace Showcase Pricing Features

Compare numbers of 2 "things" in 2 Repeating Groups

I’m building a comparison page for my app, where you can compare foods.

On the page I’ll have the nutrients for Food 1 displayed and next to that I’ll have the nutrients for Food 2.

.

I want to provide a summary below this table telling you how much Food 1 is higher in certain nutrients versus Food 2. Like below…

How would I compare numbers between the two things/RGs and figure out how much a nutrient is greater than the other food’s nutrient?

Screen Shot 2020-11-03 at 6.35.51 PM

Anyone?? Thanks! :pray:

Also interested in this exact same issue

Hi @alex.pethick @just77!

Let me take a stab at this.

There are several ways to do this. As follows could be one way:

Foundation:

  • Thing will be called an “Ingredient” and will have 2 fields for explanation purposes: Name (text), and Grams (number)
  • Repeating groups will be called RG1 and RG2. Both will have content type “ingredient” and their data sources will be “search for ingredients”. In your real app, use search constraints as needed for each RG search.
  • Create two custom states on the page that the RGs are in, which will be called “grams1” and “grams2”. Both with type “number”.

Summary

  • User clicks on their preferred row of RG1 which loads the grams value to grams1 (the first custom state). Then does the same for RG2 which loads this second grams value to grams2

Logic

  • When a row from RG1 or RG2 is clicked load the row’s ingredient to the page custom state respectively. This is done thorugh the action “set custom state”. Example: Event: when a user clicks this RG row, Action: set current cell’s ingredient grams value to page grams1
  • Write the corresponding expressions in the why answers (2.53x more proteins … etc etc). Example: “page grams1 value / page grams2 value” more proteins per 100g
  • Optional: Condition the why question (why is chickpead better than tofu…) to show comparisons only if the custom states are not empty

I know that the explanation is not super specific. Hope this makes some sense anyways and provides you guys with basic guidance to get you going.

Cheers!

1 Like

Hey @cmarchan,

Thanks for taking a stab at it, but it wasn’t exactly what I was looking for (probably my fault as you didn’t have all the info)

@just77 here’s how I did it…

I have two repeating groups:

  1. RG Comparerg1 (data source = Get comparerg1 from page URL’s food_nutrients)
    2 RG Compare2 (data source = Get comparerg2 from page URL’s food_nutrients)

The parameters mentioned above are unique id’s from the food (thing).

I then have a summary RG below these two RGs and I was able to use this dynamic data on a text field to get the desired outcome.

If you have any other questions, just let me know and I’ll try and help

I am glad things worked out. :+1:

Great! Thanks for sharing! In case it is helpful was able to apply some of what I found in this video to some effect.

This topic was automatically closed after 70 days. New replies are no longer allowed.