Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
I am trying to get the text between following pattern with DAX:
__ tjer 3(4x22) D __
______ T__r RTY 15x48.8kg TY A_
PS: the underscore is just to hide the data, assume it is any character.
I would need the numbers before the x. in the examples above that would be 4 and 15.
I can find an occurence with the DAX below:
Solved! Go to Solution.
Hi @rssilvaba ,
Last occurrence of "x" Column =
FIND (
"@",
SUBSTITUTE (
[Column1],
"x",
"@",
LEN ( [Column1] ) - LEN ( SUBSTITUTE ( [Column1], "x", "" ) )
)
)
Last occurrence of "x" Measure =
FIND (
"@",
SUBSTITUTE (
MAX ( 'Table'[Column1] ),
"x",
"@",
LEN ( MAX ( 'Table'[Column1] ) )
- LEN ( SUBSTITUTE ( MAX ( 'Table'[Column1] ), "x", "" ) )
)
)
Then, I can get the string before the last "x".
String before the last "x" = LEFT([Column1],[Last occurrence of "x" Column]-1)
But currently I don't know how to get the last several numbers. Maybe you can try the method @swise001 provided.
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @rssilvaba ,
Last occurrence of "x" Column =
FIND (
"@",
SUBSTITUTE (
[Column1],
"x",
"@",
LEN ( [Column1] ) - LEN ( SUBSTITUTE ( [Column1], "x", "" ) )
)
)
Last occurrence of "x" Measure =
FIND (
"@",
SUBSTITUTE (
MAX ( 'Table'[Column1] ),
"x",
"@",
LEN ( MAX ( 'Table'[Column1] ) )
- LEN ( SUBSTITUTE ( MAX ( 'Table'[Column1] ), "x", "" ) )
)
)
Then, I can get the string before the last "x".
String before the last "x" = LEFT([Column1],[Last occurrence of "x" Column]-1)
But currently I don't know how to get the last several numbers. Maybe you can try the method @swise001 provided.
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @Icey , You awnser works great, I came with a well using a sloppy recursion, but this is much nicer.
Thank you very much for the detailed anwser.
This can be done using Calculated Columns
Hi @swise001 ,
Your solution seems to follow the same principle as mine, so f there are any x's on the way it will just grab it. I tried it here and the result of the position is the one number up as the measure I used. That is why I am trying to find the last occurence. Also the last column gives me an error.
The last column formula throws an error when the x is preceded by a letter/symbol. To fix it - just add some error handling:
@ImkeF , Can you help on this
Hi @rssilvaba ,
how does one know which x to take?
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 , the pattern will end with auppercase letter then a number, space and two other uppercase letters.
So if I can get the last occurrence bettween that pattern it should work fine. Here are some examples how the string ends.
N4 AW
T4 UT
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
105 | |
77 | |
67 | |
63 |
User | Count |
---|---|
144 | |
107 | |
105 | |
82 | |
69 |