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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
PBR_
Frequent Visitor

Extracting Text Using a Calculated Column (Dax) - DirectQuery Connection

In Power BI, I'm trying to create a new column (with DAX) that extracts text to the left of a dash ("-"), based on an existing column.

ColumnACalculatedColumn
AAA - 789DAAA
AAA - DWOSAAA
BBB - 8F WXBBB
BBB - 5RSBBB
CC - YXDZCC

 

Please note, the data is connected using DirectQuery so I've been running into some roadblocks using DAX.

 

Any help would be appreciated!

4 REPLIES 4
vicky_
Super User
Super User

Try this:

calculcatedColumn = LEFT([ColumnA], SEARCH("-", [ColumnA]) - 1)

The idea is that the dax will grab everything to the left (excluding the space) of the first "-" character in each row.

PBR_
Frequent Visitor

Thanks, vicky_

 

Unforunately, that formula results in this error message for me:

PBR__0-1675257825241.png

Function 'SEARCH' is not allowed as part of calculated column DAX expressions on DirectQuery models.

Oh sorry, I missed the Direct Query Part. I did some googling and this thread suggests that you can enable most DAX functions (at a cost to performance). This post further specifies that you'll need to provide all 4 arguments to the search function. I hope that works for you!

PBR_
Frequent Visitor

Thanks, vicky_!

 

Using all 4 arguments with the SEARCH function works great when linked to a DirectQuery model!

ex., SEARCH(" -",[ColumnA],1,0)

 

Unfortunately, I can't get the LEFT function to work with it (but I can get the LEFT function to work alone, if I use a single number as the <num_chars>, ex., = LEFT([ColumnA],3; unforunately that's not dynamic enough for my needs).

I imagine it is because I am not presented an option to "Allow unrestricted measures in DirectQuery mode" (even though I am using power bi desktop) as shown in the thread you linked:

PBR__0-1675458341430.png

 

I have tried the following with no luck (they all give an OLE DB or ODBC expression error):

CalculatedColumn = LEFT([COLUMNA], SEARCH("-", [COLUMNA],1,0) - 1)
CalculatedColumn = LEFT([COLUMNA],(SEARCH("-", [COLUMNA],1,0)-1))
CalculatedColumn = LEFT([COLUMNA],FIND("-",[COLUMNA],1,0))

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.