# Charts custom query in RadSystems 8.5.9

**URL:** <https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832>\
**Category:** Questions\
**Created:** [November 24, 2023, 12:56am UTC](https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832 "2023-11-24T00:56:03Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ruandru](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@ruandru](https://forum.radsystems.io/u/ruandru)\
**Post date:** [November 24, 2023, 12:56am UTC](https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832/1 "2023-11-24T00:56:03Z")

</div>

Hello friends,

I have built a charts through querying my table that basically lists type of expense (food, services, etc). The chart works perfectly… But I have not been able to condition it to the data entered by each user. User independent shows all table data on expense type. Through User Records Management I have configured it so that each user sees his own records… but the chart shows him all the data, not what he has recorded.

I have tried configuring the query with WHERE and AND, through the User ID, I tried through Query\_params but it hasn’t worked for me. I appreciate if you can give me some help. @willvin

---

<div class="post-metadata">

**Author:** ![willvin](https://forum.radsystems.io/user_avatar/forum.radsystems.io/willvin/32/7_2.png) [@willvin](https://forum.radsystems.io/u/willvin)\
**Post date:** [November 25, 2023, 12:32am UTC](https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832/2 "2023-11-25T00:32:40Z")

</div>

Hi,  
What project type are you working with?

---

<div class="post-metadata">

**Author:** ![ruandru](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@ruandru](https://forum.radsystems.io/u/ruandru)\
**Post date:** [November 25, 2023, 12:46am UTC](https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832/3 "2023-11-25T00:46:42Z")

</div>

LARAVEL + bootstrap 🙂

---

<div class="post-metadata">

**Author:** ![willvin](https://forum.radsystems.io/user_avatar/forum.radsystems.io/willvin/32/7_2.png) [@willvin](https://forum.radsystems.io/u/willvin)\
**Post date:** [November 25, 2023, 11:04am UTC](https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832/4 "2023-11-25T11:04:02Z")

</div>

Add this to your query

```auto
WHERE field = :field

```

and add this to the query parameter section

```auto
$query_params['field'] = auth()->user()->user_id;

```

Replace the **field** with the table field name you want to filter the record by, and **user\_id** is the field from the user table.

 ![image](https://forum.radsystems.io/uploads/default/original/2X/d/d16a7ee91ec045f8736175c50db84f57c4c5d760.png)

---

<div class="post-metadata">

**Author:** ![ruandru](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@ruandru](https://forum.radsystems.io/u/ruandru)\
**Post date:** [November 26, 2023, 12:28am UTC](https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832/5 "2023-11-26T00:28:10Z")

</div>

Hello my friend, Thank you!!! It worked perfectly following your recommendation. However, I tell you that it worked for me in the Record Count module, I applied the query that you indicated and it works instantly… But I try to use a Chart and in the chart if it doesn’t work, and I’m using the same table, I don’t know If it’s because I’m grouping the field options there… could you shed some light on it, because it didn’t work there.

SELECT COUNT(Viaticos.id) AS count\_of\_id, Viaticos.asignacion FROM Viaticos GROUP BY Viaticos.asignacion WHERE user=:user

$query\_params[‘user’] = auth()-\>user()-\>id;

---

<div class="post-metadata">

**Author:** ![ruandru](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@ruandru](https://forum.radsystems.io/u/ruandru)\
**Post date:** [November 26, 2023, 2:29am UTC](https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832/6 "2023-11-26T02:29:11Z")

</div>

Hello friend: UPDATE. I adjusted the script by prepending the WHERE before the GROUP BY and now it works!

---

<div class="post-metadata">

**Author:** ![yoherad](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/y/0ea827/32.png) [@yoherad](https://forum.radsystems.io/u/yoherad)\
**Post date:** [December 18, 2023, 4:50pm UTC](https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832/7 "2023-12-18T16:50:01Z")

</div>

I am using the same way to record user’s account with the record method shown above. However, If the user is new and never had any record, it should return 0. However, I am getting error message for the null response. I wanted to add a code to check the output is null or number and couldn’t do that from the window above to add the code. How to handle such issues?

 ![image](https://forum.radsystems.io/uploads/default/original/2X/2/2c30ba9f68edd736152767f305ba41103d3c9e21.png)

---

<div class="post-metadata">

**Author:** ![willvin](https://forum.radsystems.io/user_avatar/forum.radsystems.io/willvin/32/7_2.png) [@willvin](https://forum.radsystems.io/u/willvin)\
**Post date:** [December 28, 2023, 9:29am UTC](https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832/8 "2023-12-28T09:29:25Z")

</div>

Read here [sql - Detect if value is number in MySQL - Stack Overflow](https://stackoverflow.com/questions/5064977/detect-if-value-is-number-in-mysql) and see how you can rewrite your query to work the way you want.

---

<div class="post-metadata">

**Author:** ![hendryres](https://forum.radsystems.io/user_avatar/forum.radsystems.io/hendryres/32/1109_2.png) [@hendryres](https://forum.radsystems.io/u/hendryres)\
**Post date:** [May 6, 2024, 8:00am UTC](https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832/9 "2024-05-06T08:00:13Z")

</div>

Sorry to join this chat,

I have something to ask you.

What if a parameter takes a value from another table?

```auto
$query_params['field'] = tax()->tax_id;

```

---

<div class="post-metadata">

**Author:** ![willvin](https://forum.radsystems.io/user_avatar/forum.radsystems.io/willvin/32/7_2.png) [@willvin](https://forum.radsystems.io/u/willvin)\
**Post date:** [May 7, 2024, 11:46am UTC](https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832/10 "2024-05-07T11:46:02Z")

</div>

it is possible if you can write your query to pull the specific data you want to use and then pass it to the parameter. Note, that this `auth()->user()->id` is automatically handled by the app, more like a session. you cannot call `tax()->tax_id` unless you have created such a function to pull your tax data.

---

<div class="post-metadata">

**Author:** ![aldrin](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/a/a88e4f/32.png) [@aldrin](https://forum.radsystems.io/u/aldrin)\
**Post date:** [June 28, 2024, 1:47am UTC](https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832/11 "2024-06-28T01:47:21Z")

</div>

how can i achieve this??

---

<div class="post-metadata">

**Author:** ![highcall](https://forum.radsystems.io/letter_avatar_proxy/v4/letter/h/c5a1d2/32.png) [@highcall](https://forum.radsystems.io/u/highcall)\
**Post date:** [December 23, 2024, 5:15am UTC](https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832/12 "2024-12-23T05:15:20Z")

</div>

how to limit record show in chart. example : limit 10 record

---

<div class="post-metadata">

**Author:** ![willvin](https://forum.radsystems.io/user_avatar/forum.radsystems.io/willvin/32/7_2.png) [@willvin](https://forum.radsystems.io/u/willvin)\
**Post date:** [December 24, 2024, 6:43pm UTC](https://forum.radsystems.io/t/charts-custom-query-in-radsystems-8-5-9/1832/13 "2024-12-24T18:43:59Z")

</div>

Add it to your query “ **LIMIT 10** ” Read here on how to do it, assuming you are using **MySQL** or **MariaDB**. Learn more here [MySQL LIMIT](https://www.w3schools.com/mysql/mysql_limit.asp)
