# "Format String" Transformation error when NULL values are present

**URL:** <https://community.grafana.com/t/format-string-transformation-error-when-null-values-are-present/149833>\
**Category:** Stat Panel\
**Tags:** transformations\
**Created:** [May 6, 2025, 9:44pm UTC](https://community.grafana.com/t/format-string-transformation-error-when-null-values-are-present/149833 "2025-05-06T21:44:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![cayse](https://avatars.discourse-cdn.com/v4/letter/c/ea666f/32.png) [@cayse](https://community.grafana.com/u/cayse)\
**Post date:** [May 6, 2025, 9:44pm UTC](https://community.grafana.com/t/format-string-transformation-error-when-null-values-are-present/149833/1 "2025-05-06T21:44:32Z")

</div>

- _What Grafana version and what operating system are you using?_  
v11.4.1

- _What are you trying to achieve?_  
Apply a Format String transformation to a field that contains some null values.

- _How are you trying to achieve it?_  
I have a Stat panel pulled from SQL data that displays Distinct Counts of values in each field. I use the Transformations tab to apply a Format String → Trim transformation to one of the fields.

- _What happened?_  
“Error transforming data: Cannot read properties of null (reading ‘trim’)”  
There are some null values in this field, which seem to be causing the transformation to not work. I do not want to filter out those rows, though, as that will throw off the counts of the other fields in the Stat panel.

- _What did you expect to happen?_  
The transformation to Trim any non-null values in the field (remove leading and trailing spaces). Some values are being counted as distinct where they should not be because of these spaces.

Is there some way to make the transformation ignore the null values? Or apply some other transformation beforehand that will convert the null values to “something else”?

---

<div class="post-metadata">

**Author:** ![infofcc3](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/infofcc3/32/51248_2.png) [@infofcc3](https://community.grafana.com/u/infofcc3)\
**Post date:** [May 7, 2025, 6:13am UTC](https://community.grafana.com/t/format-string-transformation-error-when-null-values-are-present/149833/2 "2025-05-07T06:13:50Z")

</div>

> [@cayse](#):
>
> “Error transforming data: Cannot read properties of null (reading ‘trim’)”  
> There are some null values in this field, which seem to be causing the transformation to not work. I do not want to filter out those rows, though, as that will throw off the counts of the other fields in the Stat panel.

You are getting this error in Grafana:  
**“Error transforming data: Cannot read properties of null (reading ‘trim’)”**  
This happens because your data has **null values** , and Grafana cannot use the **Trim** function on null.  
try this in query  
`COALESCE(TRIM(department), 'Unknown') AS cleaned_department`  
Note: `TRIM(department)` removes spaces & COALESCE(…, ‘Unknown’) replaces null with the word **“Unknown”**.  
You get clean data.

---

<div class="post-metadata">

**Author:** ![cayse](https://avatars.discourse-cdn.com/v4/letter/c/ea666f/32.png) [@cayse](https://community.grafana.com/u/cayse)\
**Post date:** [May 7, 2025, 3:58pm UTC](https://community.grafana.com/t/format-string-transformation-error-when-null-values-are-present/149833/3 "2025-05-07T15:58:56Z")

</div>

Thank you for the quick response. Is there a way to do this purely through Transformations? This panel is using another panel in the dashboard as the source rather than its own query, and there are other panels doing the same that are filtering on null. I’d like to avoid having to change the Transformations in the other panels if possible.

Alternatively, is there somewhere I can request that the Format String transformation ignore Null values so it will work in this scenario? Sorry if that’s a newb question, but I’m new here. 🙂

---

<div class="post-metadata">

**Author:** ![infofcc3](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/infofcc3/32/51248_2.png) [@infofcc3](https://community.grafana.com/u/infofcc3)\
**Post date:** [May 8, 2025, 6:03am UTC](https://community.grafana.com/t/format-string-transformation-error-when-null-values-are-present/149833/4 "2025-05-08T06:03:05Z")

</div>

![image](https://us1.discourse-cdn.com/grafana/original/3X/0/e/0e54dfddcf80070f7867e97eec01c8cfe24f5b74.png)  
Use this convert field type it will conver you null to string and after that use Format string transformation now it will not give any error.  
 ![image](https://us1.discourse-cdn.com/grafana/original/3X/c/2/c2540cc6df8413c636ebee6af0a1ded203a3875a.png)

---

<div class="post-metadata">

**Author:** ![yosiasz](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/yosiasz/32/45847_2.png) [@yosiasz](https://community.grafana.com/u/yosiasz)\
**Post date:** [May 8, 2025, 12:34pm UTC](https://community.grafana.com/t/format-string-transformation-error-when-null-values-are-present/149833/5 "2025-05-08T12:34:04Z")

</div>

I would recommend you use coalesce or isnull type of function to give it a non null value like empty string unless that approach breaks your aggregation etc

Please post some sample data for which you are having issues with

---

<div class="post-metadata">

**Author:** ![cayse](https://avatars.discourse-cdn.com/v4/letter/c/ea666f/32.png) [@cayse](https://community.grafana.com/u/cayse)\
**Post date:** [May 8, 2025, 4:12pm UTC](https://community.grafana.com/t/format-string-transformation-error-when-null-values-are-present/149833/6 "2025-05-08T16:12:37Z")

</div>

I should have known! 😂 Thank you, this works perfectly

---

<div class="post-metadata">

**Author:** ![infofcc3](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/infofcc3/32/51248_2.png) [@infofcc3](https://community.grafana.com/u/infofcc3)\
**Post date:** [May 9, 2025, 5:08am UTC](https://community.grafana.com/t/format-string-transformation-error-when-null-values-are-present/149833/7 "2025-05-09T05:08:52Z")

</div>

Thanks @cayse for your feedback 😊.
