# Adjust the \`Let\` function

**URL:** <https://the.fmsoup.org/t/adjust-the-let-function/4757>\
**Category:** Questions\
**Created:** [March 22, 2025, 4:16am UTC](https://the.fmsoup.org/t/adjust-the-let-function/4757 "2025-03-22T04:16:56Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saeed](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Saeed](https://the.fmsoup.org/u/Saeed)\
**Post date:** [March 22, 2025, 4:16am UTC](https://the.fmsoup.org/t/adjust-the-let-function/4757/1 "2025-03-22T04:16:56Z")

</div>

I need to adjust the `Let` function to specifically count the meeting rooms, as shown in the snapshot. I have two meeting rooms, but the dashboard shows three instead of two because it is counting the asset rows.

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/e/e8a7b89fb9d0139afa4d3e3a447c9a26911b28f7.png)

Let (  
[  
selectedDate = Get ( CurrentDate );  
meetingroomCount = ExecuteSQL ( "  
SELECT COUNT(\*)  
FROM Inventory\_Asset\_List  
WHERE "Date" = ?  
AND Department = 'Meeting Room'  
" ; "" ; "" ; Get ( CurrentDate ))  
];

```
"MR. ¶" & TextSize ( meetingroomCount; 20)

```

)

---

<div class="post-metadata">

**Author:** ![EdwinS](https://avatars.discourse-cdn.com/v4/letter/e/57b2e6/32.png) [@EdwinS](https://the.fmsoup.org/u/EdwinS)\
**Post date:** [March 22, 2025, 5:38am UTC](https://the.fmsoup.org/t/adjust-the-let-function/4757/2 "2025-03-22T05:38:47Z")

</div>

- Why is '"Date"' in quotes? This certainly does not refer to a field.
- What is the 'selectedDate' variable used for?
- Other than that, I don't really understand your question.

---

<div class="post-metadata">

**Author:** ![xochi](https://avatars.discourse-cdn.com/v4/letter/x/0ea827/32.png) [@xochi](https://the.fmsoup.org/u/xochi)\
**Post date:** [March 22, 2025, 2:32pm UTC](https://the.fmsoup.org/t/adjust-the-let-function/4757/3 "2025-03-22T14:32:22Z")

</div>

Rather than SQL, I would approach this using normal FileMaker relationships and calculations, where you have a relationship between this table and the Inventory\_Asset\_List table, using calculated fields for today's date and the room Department "meeting rooms" (or use global fields, if you want to change the dates and room types).

Then, If each row of the asset contains the foreign key for the Meeting room, you could simply do this:

`meetingRoomCount = ValueCount(UniqueValues(List(Inventory_asset_list_by_Date_And_Department::roomID)))`

---

<div class="post-metadata">

**Author:** ![Bobino](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/bobino/32/194_2.png) [@Bobino](https://the.fmsoup.org/u/Bobino)\
**Post date:** [March 22, 2025, 9:50pm UTC](https://the.fmsoup.org/t/adjust-the-let-function/4757/4 "2025-03-22T21:50:16Z")

</div>

instead of using COUNT( \* ), count the field with your meeting room name and use distinct on that.

See a reference here: [Aggregate functions](https://help.claris.com/en/sql-reference/content/aggregate-functions.html)

---

<div class="post-metadata">

**Author:** ![Kirk](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/kirk/32/2197_2.png) [@Kirk](https://the.fmsoup.org/u/Kirk)\
**Post date:** [March 23, 2025, 1:01am UTC](https://the.fmsoup.org/t/adjust-the-let-function/4757/5 "2025-03-23T01:01:19Z")

</div>

You could also do this with a while calculation

One of the key issues with sql in FM that should preclude using it extensively; if there is an open record in the found set, eSQL will wait until all records are not locked.

Results in high variability in performance.

---

<div class="post-metadata">

**Author:** ![OliverBarrett](https://avatars.discourse-cdn.com/v4/letter/o/f19dbf/32.png) [@OliverBarrett](https://the.fmsoup.org/u/OliverBarrett)\
**Post date:** [March 23, 2025, 11:59am UTC](https://the.fmsoup.org/t/adjust-the-let-function/4757/6 "2025-03-23T11:59:15Z")

</div>

I believe Date is a reserved word in FileMaker SQL syntax.

I'd recommend renaming the field and using a third-party SQL tool like DataGrip (or similar) to fine-tune your SQL.

I prefer SQL in cases like this or anywhere when possible in FileMaker, since SQL is an industry standard.

---

<div class="post-metadata">

**Author:** ![planteg](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/planteg/32/627_2.png) [@planteg](https://the.fmsoup.org/u/planteg)\
**Post date:** [March 23, 2025, 10:24pm UTC](https://the.fmsoup.org/t/adjust-the-let-function/4757/7 "2025-03-23T22:24:37Z")

</div>

> [@OliverBarrett](#):
>
> I believe Date is a reserved word in FileMaker SQL syntax.

Right, see [Reserved words in FileMaker Pro](https://support.claris.com/s/article/Reserved-words-in-FileMaker-Pro-1503693036814?language=en_US)

---

<div class="post-metadata">

**Author:** ![DanShockley](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@DanShockley](https://the.fmsoup.org/u/DanShockley)\
**Post date:** [March 24, 2025, 6:29pm UTC](https://the.fmsoup.org/t/adjust-the-let-function/4757/8 "2025-03-24T18:29:51Z")

</div>

Agreed that you should be careful with how/when you use ExecuteSQL. But, I have not heard of an issue where it will just wait (forever?) until all records are not locked. Kirk, if you've seen that, I'd be interested in hearing more details.

The "gotcha" I'm aware of is similar, but is this:  
If the client running the ExecuteSQL query has uncommitted records in that target table, the server will say "you have potential edits in that table, so you (the client) must run the query yourself. Here is ALL the data for ALL the records in the table: good luck."  
Now, if the table is fairly small, that's not so bad. But, if the table has many thousands (or millions!) of records, the server has to transfer all that data to the client, and then the client does the query.  
ExecuteSQL is built that way so that its results match the way FileMaker has always worked: the client knows about and can include its own uncommitted changes. But, the big downside is that queries normally done BY the server, and thus often very fast, might instead take a VERY long time while the entire contents of the table are transferred to the client over the network.

---

<div class="post-metadata">

**Author:** ![Kirk](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/kirk/32/2197_2.png) [@Kirk](https://the.fmsoup.org/u/Kirk)\
**Post date:** [March 24, 2025, 6:44pm UTC](https://the.fmsoup.org/t/adjust-the-let-function/4757/9 "2025-03-24T18:44:15Z")

</div>

> [@DanShockley](#):
>
> I'd be interested in hearing more details.

> **[FileMaker ExecuteSQL() - the Good, the Bad and the Ugly](https://www.soliantconsulting.com/blog/executesql-filemaker-performance/)**
>
> FileMaker ExecuteSQL() can be very powerful, but you must use it correctly within its limits. Learn more from our top FileMaker developers.

---

<div class="post-metadata">

**Author:** ![DanShockley](https://avatars.discourse-cdn.com/v4/letter/d/9f8e36/32.png) [@DanShockley](https://the.fmsoup.org/u/DanShockley)\
**Post date:** [March 24, 2025, 9:53pm UTC](https://the.fmsoup.org/t/adjust-the-let-function/4757/10 "2025-03-24T21:53:28Z")

</div>

Right - that article is describing in more detail what I described above: the query becomes slower when the client _trying to run the query_ has an open record in the table targeted by the query, for the reason I described above.

I thought perhaps you had heard of some other potential issue where the eSQL query would actually _never_ complete until the records were committed. And, your comment implied that _anyone_ having open records could cause this problem, when it is much more specific than that.

Also, the query does not "wait until all records are not locked". It takes longer, but it does not pause/wait. It will run, but potentially very slowly, if the specific circumstances described occur.

---

<div class="post-metadata">

**Author:** ![OliverBarrett](https://avatars.discourse-cdn.com/v4/letter/o/f19dbf/32.png) [@OliverBarrett](https://the.fmsoup.org/u/OliverBarrett)\
**Post date:** [March 25, 2025, 9:43am UTC](https://the.fmsoup.org/t/adjust-the-let-function/4757/11 "2025-03-25T09:43:47Z")

</div>

Try running a GROUP BY query with only 50,000 records if you want to see FileMaker really hung! Yes, I know, I know, .... "FileMaker is not a SQL Database!". LOL.  
(I just did a GROUP BY query on MariaDB (free) with 8 Million records in 4.5 seconds.)

---

<div class="post-metadata">

**Author:** ![Saeed](https://avatars.discourse-cdn.com/v4/letter/s/e8c25b/32.png) [@Saeed](https://the.fmsoup.org/u/Saeed)\
**Post date:** [March 26, 2025, 5:04am UTC](https://the.fmsoup.org/t/adjust-the-let-function/4757/12 "2025-03-26T05:04:33Z")

</div>

I would like to express my gratitude to everyone for sharing their suggestions and for their ongoing efforts in resolving this issue. Below are my solution based on the requirements.

Let (  
[  
today = Get ( CurrentDate ) ;  
result = ExecuteSQL (  
"SELECT COUNT(DISTINCT "Employee\_Name")  
FROM Inventory\_Asset\_List  
WHERE Department = ?  
AND "Date"= ?" ;  
"" ; "" ;  
"Meeting Room" ; today  
)  
] ;  
"MR. ¶" & TextSize ( result; 20)  
)

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/f/f1a214289046caa127a8157692ad5ff599354a3b.png)
