Forum Discussion
DAX: extracting string using delimiter
- 8 years ago
Hey,
besides the fact that I would try to create the columns using the Query Editor here are two DAX Statements to create Calculated Columns
First Derived Column = var FirstColon = FIND(":",'Table1'[Origin Column],1) var SecondColon = FIND(":",'Table1'[Origin Column],FirstColon + 1) var ThirdColon = FIND(":",'Table1'[Origin Column],SecondColon + 1) return MID('Table1'[Origin Column], SecondColon + 1, ThirdColon - SecondColon - 1)and
Second Derived Column = var FirstColon = FIND(":",'Table1'[Origin Column],1) var SecondColon = FIND(":",'Table1'[Origin Column],FirstColon + 1) var ThirdColon = FIND(":",'Table1'[Origin Column],SecondColon + 1) var LengthOfString = LEN('Table1'[Origin Column]) return MID('Table1'[Origin Column],ThirdColon + 1, LengthOfString - ThirdColon + 1)this would create the following
- 8 years ago
As TomMartens mentioned already, this task can easier be done in Power Query /the query editor in PBI.
If you want to extract the values between the 2nd and 3rd colon delimiter, you add a column with this formula:
Text.Split([Value], ":"){2}It splits the text on each colon and returns a list of the separated values. To fetch the 3rd value from the list you use {2} because the count starts at zero here.
To extract the values after the last colon, there is a nice user interface for it:
It results in this formula:
Text.AfterDelimiter([Value], ":", {0, RelativePosition.FromEnd})
Hey,
besides the fact that I would try to create the columns using the Query Editor here are two DAX Statements to create Calculated Columns
First Derived Column =
var FirstColon = FIND(":",'Table1'[Origin Column],1)
var SecondColon = FIND(":",'Table1'[Origin Column],FirstColon + 1)
var ThirdColon = FIND(":",'Table1'[Origin Column],SecondColon + 1)
return
MID('Table1'[Origin Column], SecondColon + 1, ThirdColon - SecondColon - 1)and
Second Derived Column =
var FirstColon = FIND(":",'Table1'[Origin Column],1)
var SecondColon = FIND(":",'Table1'[Origin Column],FirstColon + 1)
var ThirdColon = FIND(":",'Table1'[Origin Column],SecondColon + 1)
var LengthOfString = LEN('Table1'[Origin Column])
return
MID('Table1'[Origin Column],ThirdColon + 1, LengthOfString - ThirdColon + 1)this would create the following
- ImkeF8 years agoCommunity Champion
As TomMartens mentioned already, this task can easier be done in Power Query /the query editor in PBI.
If you want to extract the values between the 2nd and 3rd colon delimiter, you add a column with this formula:
Text.Split([Value], ":"){2}It splits the text on each colon and returns a list of the separated values. To fetch the 3rd value from the list you use {2} because the count starts at zero here.
To extract the values after the last colon, there is a nice user interface for it:
It results in this formula:
Text.AfterDelimiter([Value], ":", {0, RelativePosition.FromEnd})- Manichin3 years agoFrequent Visitor
Hi ImkeF, Thank you for your input. I have the same situation where i need to get a key:value pair which is not in the same no of key value pair ineachcolumn. 2 nd row will have 3 key:value pairs and 3 rd might have 6 key:value pairs. i need to get a specific key:value pair from that column. could you suggest how to get it. Please let me know if you need more inputs