# Formula to show the latest fuel price?

**URL:** <https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619>\
**Category:** Ask for Help\
**Created:** [December 10, 2022, 7:51am UTC](https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619 "2022-12-10T07:51:11Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guilio\_Del\_Fava](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/guilio_del_fava/32/65469_2.png) [@Guilio\_Del\_Fava](https://community.glideapps.com/u/Guilio_Del_Fava)\
**Post date:** [December 10, 2022, 7:51am UTC](https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619/1 "2022-12-10T07:51:11Z")

</div>

Hi all, i need help please.

I have a table in glide that has a date column and a fuel price per litre column. I am trying to create a lookup on that table that would find the max date and then the corresponding fuel price. Then I can show this data on the frontend to the user so they always know what the latest fuel price is.

Can someone point me in the right direction in what I need to do to accomplish this?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![Darren\_Murphy](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/darren_murphy/32/47326_2.png) [@Darren\_Murphy](https://community.glideapps.com/u/Darren_Murphy)\
**Post date:** [December 10, 2022, 7:54am UTC](https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619/2 "2022-12-10T07:54:43Z")

</div>

It’s a little bit cumbersome, but here is how you do it:

- Create a _multiple_ relation that matches the date column with itself.
- Create a rollup column that takes the latest date via the multiple relation
- Create a _single_ relation that matches the latest date (rollup) with the original date column
- Create a lookup column that takes the price via the _single_ relation column.

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [December 10, 2022, 7:57am UTC](https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619/3 "2022-12-10T07:57:31Z")

</div>

use the rollup column to find the latest date, then the if-else column: if the date is the latest date then row ID… now you can copy this row ID using a single value column to the sheet that needs relation… then relate that single value to the sheet with gas prices rowID

---

<div class="post-metadata">

**Author:** ![Guilio\_Del\_Fava](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/guilio_del_fava/32/65469_2.png) [@Guilio\_Del\_Fava](https://community.glideapps.com/u/Guilio_Del_Fava)\
**Post date:** [December 10, 2022, 8:20am UTC](https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619/5 "2022-12-10T08:20:22Z")

</div>

That worked, thank you. I was then able to set a default value for my Fuel Price field in my add refuel form. So now it shows the latest price without the user having to add it manually. Brilliant.

---

<div class="post-metadata">

**Author:** ![Guilio\_Del\_Fava](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/guilio_del_fava/32/65469_2.png) [@Guilio\_Del\_Fava](https://community.glideapps.com/u/Guilio_Del_Fava)\
**Post date:** [December 10, 2022, 8:22am UTC](https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619/6 "2022-12-10T08:22:22Z")

</div>

Thank you for your reply.

---

<div class="post-metadata">

**Author:** ![Guilio\_Del\_Fava](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/guilio_del_fava/32/65469_2.png) [@Guilio\_Del\_Fava](https://community.glideapps.com/u/Guilio_Del_Fava)\
**Post date:** [December 10, 2022, 8:24am UTC](https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619/7 "2022-12-10T08:24:34Z")

</div>

Last bit to this.

I have a Fuel Station Table that lists the Fuel Station Details, like name, location, city etc. How would I add the latest fuel price from the refuels table to this table so i can show this on the fuel station details screen on the front end?

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [December 10, 2022, 8:25am UTC](https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619/8 "2022-12-10T08:25:25Z")

</div>

use my method lol… get the row ID and relate it … you must have a Gas station row ID in the price row

---

<div class="post-metadata">

**Author:** ![Guilio\_Del\_Fava](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/guilio_del_fava/32/65469_2.png) [@Guilio\_Del\_Fava](https://community.glideapps.com/u/Guilio_Del_Fava)\
**Post date:** [December 10, 2022, 8:32am UTC](https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619/9 "2022-12-10T08:32:43Z")

</div>

Thank you, I couldn’t quite understand your method. Could you show me in more detail maybe with screenshots on how to implement it please? 🙂

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [December 10, 2022, 8:37am UTC](https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619/10 "2022-12-10T08:37:41Z")

</div>

is the price different for different gas stations? or does the latest price apply to all gas stations?

---

<div class="post-metadata">

**Author:** ![Guilio\_Del\_Fava](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/guilio_del_fava/32/65469_2.png) [@Guilio\_Del\_Fava](https://community.glideapps.com/u/Guilio_Del_Fava)\
**Post date:** [December 10, 2022, 8:45am UTC](https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619/11 "2022-12-10T08:45:47Z")

</div>

The price for Petrol is the same across all fuel stations but the price of diesel is different across all the fuel stations.

---

<div class="post-metadata">

**Author:** ![Guilio\_Del\_Fava](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/guilio_del_fava/32/65469_2.png) [@Guilio\_Del\_Fava](https://community.glideapps.com/u/Guilio_Del_Fava)\
**Post date:** [December 10, 2022, 8:48am UTC](https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619/12 "2022-12-10T08:48:09Z")

</div>

So I need to show both the Petrol Price and the Diesel price per litre on the Fuel Station detail page or as a default in the Fuel Price Field in the form. On the form i have s choice field that has the fuel types, so a user select the fuel type then the latest price could be shown in the Fuel Price field so he does not have to add it manually.

---

<div class="post-metadata">

**Author:** ![Uzo](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/uzo/32/22639_2.png) [@Uzo](https://community.glideapps.com/u/Uzo)\
**Post date:** [December 10, 2022, 8:50am UTC](https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619/13 "2022-12-10T08:50:24Z")

</div>

if is the same for all is easy… just follow my steps… for diesel … you need to add the row ID of the station when applying a new price…  
or you can use Darren method, if you already have that working, and copy that price to the table where you have your Gas Stations… use Single Value column

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)\
**Post date:** [December 11, 2022, 8:50am UTC](https://community.glideapps.com/t/formula-to-show-the-latest-fuel-price/55619/14 "2022-12-11T08:50:58Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
