March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi guys, newbie to the forum! I've recently discovered PowerPivot and it's fantastic - but do occassionaly encounter issues when converting Excel formulas to DAX-friendly formulas.
I have a column in my data model table which has values like this: Example:AA:XX-yy:1234 --> I would like to create 2 additional columns which contains only XX-yy (text between 2nd/3rd colon delimiter) and 1234 (text after the last colon delimiter)
Origin column | Desired column | Desired column 2 |
Example:AA:XX-yy:1234 | XX-yy | 1234 |
As the data refreshes from a SQL server, I want to have dynamic columns instead of using the text-to-columns function manually.
The excel formula I used before looks like this:
xx = origin cell | 2 takes the value between the 2nd/3rd colon delimter
=TRIM(LEFT(SUBSTITUTE(MID(xx,FIND("|",SUBSTITUTE(xx,":","|",2))+1,LEN(xx)),":",REPT(" ",LEN(xx))),LEN(xx)))
Any help would be greatly appreciated! Thank you!
Solved! Go to Solution.
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
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})
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
Hi @Manichin ,
you can use an additional formula on the returned result: List.Select
List.Select(<YourResultSoFar>, each Text.StartsWith(_, "KeyThatYouWant"))
This will pick that item from your value pairs, that starts with the desired text.
Or are these elements proper records already?
Otherwise please provide sample data like described here:
Upload sample data / tables: https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
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
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})
Imke Feldmann (The BIccountant)
If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!
How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries
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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
133 | |
91 | |
88 | |
64 | |
58 |
User | Count |
---|---|
201 | |
137 | |
107 | |
73 | |
68 |