Forum Discussion
SQL PATINDEX equivalent in DAX
- 6 years ago
Nothing in DAX that I am aware of that does anything like this. ImkeF , anything in Power Query?
Greg_Deckler thanks for the confirmation.
ImkeF thanks for taking time out to devise a native M solution.
In my current situation I query SQL tables and want to finish most of data transformation on SQL side as despite M being so awesome it has a performance issue. Now my SQL table has 4M+ rows and if I devise a M solution it might affect the performance. That is what I am most scared about. Before importing my tables from SQL to PBI I forgot to do this transformation and I was hoping DAX has a solution to this as despite being unnecessarily complex DAX is blazing fast. Also, Marco points out the readers here https://www.sqlbi.com/articles/comparing-dax-calculated-columns-with-power-query-computed-columns/ to do transformation in DAX for the sake of performance.
However, I appreciate you taking time out of your schedule and going extraordinary lengths to help me out. And, I am going to add a R powered M solution here to the problem as well for the sake of documenting multiple solutions to the same problem. And this query result renders in the PBI service as well.
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCilKzCtOTC7JzM9TMDQyNjE1M7fQNVSK1QFKVUD5lga6RmARKM9Q1xDCNzU1MzM3t7DQNTJQAAKwmGdemTLQJBNTcwsDsL5YAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Description = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Description", type text}}),
#"Run R script" = R.Execute("# 'dataset' holds the input data for this script#(lf)x<-dataset#(lf)x#(lf)library(stringr)#(lf)numextract <- function(string){str_extract(string, ""\\d{8}[-]\\d*"")}#(lf)x$result<-numextract(x$Description)",[dataset=#"Changed Type"]),
#"""x""" = #"Run R script"{[Name="x"]}[Value]
in
#"""x"""
Hi smpa01 ,
no problem, this method will make a good blogpost 😉
If your source in SQL, then the fastest version is probably to use a SQL-script in the query editor: https://support.office.com/en-us/article/import-data-from-database-using-native-database-query-power-query-f4f448ac-70d5-445b-a6ba-302db47a1b00