Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

SUBSITUTE function does not work correctly in DirectQuery mode

Hello everyone,

I would like to find a solution for a problem regarding the SUBSITUTE function.

 

I have a string of procceses in the following format:

[|Process1|,|Process2|,|Proces3|, ...]

 

I would like to split this string into multiple columns in order to have each process in a separat column. I find the solution, but when I tried to integrate it on one project that uses DirectQuery as Storage Mode I realize that my logic does not work because the SUBSTITUTE function accept only 3 parameters, not 4 as it works in the Import Mode.

 

The syntax I used is the following:

SUBSTITUTE(Table1[Processes_0],"|,|","*",1)
 
It does not work on DirectQuery due to the 4th parameter. I need to replace that grouping of symbols "|,|" based on the number of the instance. 
 
Could you help me please with a solution to the problem presented above?
 
Thank you! 🙂

 

 

1 ACCEPTED SOLUTION

@Anonymous Any chance you can use a measure? More DAX functions are supported in measures rather than calculated columns. Also, if you can use SUBSTITUTE in a measure and replace all occurences with "|" (pipe character) then you can use PATHITEM to retrieve individual parts instead of using FIND, MID, etc.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

5 REPLIES 5
Greg_Deckler
Super User
Super User

@Anonymous Why can't you just turn it into a PATH by replacing each instance with "|". Why do you need to replace each one individually?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi @Greg_Deckler ,

 

Thank you for your message!
For example, in order to extract the second process from a string that contains 6 processes the code is the following:

 

PR2 = IF(Table1[NumberOfProcesses]<=1,
"",
    var aux1 = SUBSTITUTE(Table1[Processes_0],"|,|","*",1)
    var aux2 = SUBSTITUTE(aux1,"|","*",2)
    var First = FIND("*",aux2,1,0)
    var Last = FIND("*",aux2,First+1,500)
    var Diff = Last-First-1
    var Final = MID(aux2,First+1,Diff)
return Final)

Is the case more clear now?
 
Thank you,
Diana 🙂 

@Anonymous Any chance you can use a measure? More DAX functions are supported in measures rather than calculated columns. Also, if you can use SUBSTITUTE in a measure and replace all occurences with "|" (pipe character) then you can use PATHITEM to retrieve individual parts instead of using FIND, MID, etc.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Hi @Greg_Deckler ,

 

Thank you a lot for the solution.

I used the PATHITEM function to split my string in multiple columns.

 

Have a wonderful day!
Dia

Anonymous
Not applicable

The errors is: 
Function 'SUBSTITUTE' is not allowed as part of calculated column DAX expressions on DirectQuery expressions on DirectQuery models.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors