Forum Discussion
Extracting complicated text from a column
- 4 months ago
Hi afaherty
Thank you for reaching out to the Microsoft Fabric community forum.
You can do this natively in Power Query without Python by splitting the list into tokens, trimming, then filtering only the items that start with INTASC/InTASC (case-insensitive). This also handles rows with multiple INTASC values and returns them joined with |.
Add a custom column with:
each let t = [Current Data], cleaned0 = if t = null or Text.Trim(t) = "" then null else t, cleaned = if cleaned0 = null then null else Text.Replace( Text.Replace( Text.Replace( Text.Replace(cleaned0, "[", ""), "]", ""), "(", ""), ")", ""), parts = if cleaned = null then {} else List.Transform( Splitter.SplitTextByAnyDelimiter({",", ";"}, QuoteStyle.Csv)(cleaned), each Text.Trim(_) ), intascOnly = List.Select( parts, each Text.StartsWith(Text.Trim(_), "INTASC", Comparer.OrdinalIgnoreCase) ), result = if List.Count(intascOnly) = 0 then null else Text.Combine(intascOnly, " | ") in resultThis will return InTASC 10m | INTASC 61s when multiple values exist, or blank/null if none are present.
Hope this helps clarify things and let me know what you find after giving these steps a try happy to help you investigate this further.Regards,
Microsoft Fabric Community Support Team
- 4 months ago
Hi afaherty
Since the text can contain words before the brackets, the correct approach is to first extract only the content inside [ ... ], then split and filter for InTASC.Add a custom column with.
each let t = [Current Data], insideBrackets = if t = null then null else try Text.BetweenDelimiters(t, "[", "]") otherwise null, parts = if insideBrackets = null then {} else List.Transform( Splitter.SplitTextByAnyDelimiter({",", ";"}, QuoteStyle.Csv)(insideBrackets), each Text.Trim(Text.Clean(_)) ), intascOnly = List.Select( parts, each Text.StartsWith(_, "INTASC", Comparer.OrdinalIgnoreCase) ), result = if List.Count(intascOnly) = 0 then null else Text.Combine(intascOnly, " | ") in result
This will correctly return InTASC 3n | InTASC 8c for multiple matches, InTASC 5b for a single match, or null if no match is found.
If you have any other questions, feel free to contact us. We're here to help.Regards,
Microsoft Fabric Community Support Team.
Hi afaherty
The issue is caused by hidden or non-printable characters in the first token. When the string starts directly with InTASC, those characters can prevent Text.StartsWith from matching correctly, even after trimming. That’s why the first value is being skipped, while subsequent values (after commas) work fine.
Applying Text.Clean and normalizing the text before filtering resolves this.
Add a custom column with:
each
let
t = [Current Data],
cleaned0 =
if t = null or Text.Trim(t) = ""
then null
else t,
cleaned =
if cleaned0 = null
then null
else Text.Replace(
Text.Replace(
Text.Replace(
Text.Replace(cleaned0, "[", ""),
"]", ""),
"(", ""),
")", ""),
parts =
if cleaned = null
then {}
else List.Transform(
Splitter.SplitTextByAnyDelimiter({",", ";"}, QuoteStyle.Csv)(cleaned),
each Text.Upper(Text.Trim(Text.Clean(_)))
),
intascOnly =
List.Select(
parts,
each Text.StartsWith(_, "INTASC")
),
result =
if List.Count(intascOnly) = 0
then null
else Text.Combine(intascOnly, " | ")
in
result
This ensures the first InTASC value is correctly detected and also continues to handle multiple matches as expected.
I hope this clarifies things. Let me know what you find after trying these steps. We will assist you further.
Regards,
Microsoft Fabric Community Support Team.
Hi! Thank you v-karpurapud ! So something I failed to mention is that there are words prior to every starting bracket [ in the cell
So, each cell looks something like: Words words words [InTASC 3n, InTASC 8c]
And so from "Words words words [InTASC 3n, InTASC 8c]" I am trying to pull out InTASC 3n | InTasc 8c
- v-karpurapud4 months ago
Community Support
Hi afaherty
Since the text can contain words before the brackets, the correct approach is to first extract only the content inside [ ... ], then split and filter for InTASC.Add a custom column with.
each let t = [Current Data], insideBrackets = if t = null then null else try Text.BetweenDelimiters(t, "[", "]") otherwise null, parts = if insideBrackets = null then {} else List.Transform( Splitter.SplitTextByAnyDelimiter({",", ";"}, QuoteStyle.Csv)(insideBrackets), each Text.Trim(Text.Clean(_)) ), intascOnly = List.Select( parts, each Text.StartsWith(_, "INTASC", Comparer.OrdinalIgnoreCase) ), result = if List.Count(intascOnly) = 0 then null else Text.Combine(intascOnly, " | ") in result
This will correctly return InTASC 3n | InTASC 8c for multiple matches, InTASC 5b for a single match, or null if no match is found.
If you have any other questions, feel free to contact us. We're here to help.Regards,
Microsoft Fabric Community Support Team.
- afaherty4 months ago
Helper V
Amazing!! Thank you!!