# How to replace multiple strings in the same Expression/field using replaceString function

**URL:** <https://community.dynatrace.com/t/how-to-replace-multiple-strings-in-the-same-expression-field-using-replacestring-function/51606>\
**Category:** DQL\
**Tags:** dql\
**Created:** [May 13, 2025, 10:48am UTC](https://community.dynatrace.com/t/how-to-replace-multiple-strings-in-the-same-expression-field-using-replacestring-function/51606 "2025-05-13T10:48:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaladhar](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@Kaladhar](https://community.dynatrace.com/u/Kaladhar)\
**Post date:** [May 13, 2025, 10:48am UTC](https://community.dynatrace.com/t/how-to-replace-multiple-strings-in-the-same-expression-field-using-replacestring-function/51606/1 "2025-05-13T10:48:39Z")

</div>

Hi Team,

I have this requirement to replace multiple strings in an&nbsp;expression which is having two different&nbsp;substrings.

For the Example below:

Category field has two results either A or B and I want to replace ‘A’ with ‘XML’ and ‘B’ with ‘TEXT’.

I have used below command with&nbsp; **replaceString** and it worked for ‘A’.

_fieldsAdd replaceString(Category, “A”, “XML”)_

How do I replace the another string B in the same&nbsp;Category field(without adding new&nbsp; **fieldsAdd** command.)

Thanks,

---

<div class="post-metadata">

**Author:** ![krzysztof\_hoja](https://dub1.discourse-cdn.com/dynatrace/user_avatar/community.dynatrace.com/krzysztof_hoja/32/34625_2.png) [@krzysztof\_hoja](https://community.dynatrace.com/u/krzysztof_hoja)\
**Post date:** [May 13, 2025, 8:28pm UTC](https://community.dynatrace.com/t/how-to-replace-multiple-strings-in-the-same-expression-field-using-replacestring-function/51606/2 "2025-05-13T20:28:52Z")

</div>

if “Category field has two results either A or B” why do you need _ **replaceString** _, not just _ **if** _?

If my understanding of assumption is correct, this could look like this:

```markup
data record(Category="A"),
record(Category="B")
| fieldsAdd Category = coalesce(
  if(Category=="A","XML"),
  if(Category=="B","TEXT"))

```

 ![krzysztof_hoja_0-1747168120207.png](https://global.discourse-cdn.com/dynatrace/original/3X/c/6/c6bb6786f8c4899ff431f2ae96b510b5c85f7b35.png)

---

<div class="post-metadata">

**Author:** ![MuhammadGamal](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@MuhammadGamal](https://community.dynatrace.com/u/MuhammadGamal)\
**Post date:** [May 13, 2025, 9:08pm UTC](https://community.dynatrace.com/t/how-to-replace-multiple-strings-in-the-same-expression-field-using-replacestring-function/51606/3 "2025-05-13T21:08:26Z")

</div>

Can you try this :  
| fieldsAdd CategoryReplaced = replaceString(replaceString(Category, “A”, “XML”), “B”, “TEXT”)  
please check the simple Example :

 ![MuhammadGamal_0-1747170555778.png](https://global.discourse-cdn.com/dynatrace/original/3X/9/7/976d801b5f9a70570e88ee03040ba78bb7071c26.png)

 ![MuhammadGamal_1-1747170649215.png](https://global.discourse-cdn.com/dynatrace/original/3X/e/5/e5a8005ce39147e0937faf40801f588650fb698f.png)

---

<div class="post-metadata">

**Author:** ![Kaladhar](https://avatars.discourse-cdn.com/v4/letter/k/258eb7/32.png) [@Kaladhar](https://community.dynatrace.com/u/Kaladhar)\
**Post date:** [May 14, 2025, 8:46am UTC](https://community.dynatrace.com/t/how-to-replace-multiple-strings-in-the-same-expression-field-using-replacestring-function/51606/4 "2025-05-14T08:46:15Z")

</div>

This works too. Thank you for the response.

I was looking to get my hands on ‘string functions’ by dynatrace also more results might be added in the future.
