Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
ysherriff
Resolver II
Resolver II

M Code to extract between characters that are not same position

Hi all,

Does anyone know how to extract the year from this text string? I trired "Text Extraction" and "Delimiter" but it is not coming out the way I want.

I want the year in one column but I am also showing "Gen".


Thank you for your help

 

ysherriff_0-1668711469393.png

 

1 ACCEPTED SOLUTION

Thank you but this solution works


List.RemoveNulls (
List.Transform (
Text.Split ( _[Campaign Name], "-" ),
each try Number.From ( _ ) otherwise null
)
){0}

 

 

ysherriff_0-1668724064023.png

 

View solution in original post

2 REPLIES 2
Daryl-Lynch-Bzy
Resident Rockstar
Resident Rockstar

Hi @ysherriff - you could try something like Text.Remove - PowerQuery M | Microsoft Learn or Text.Select - PowerQuery M | Microsoft Learn

 

Select = Text.Select( [Text] , {"0".."9"} )
Remove = Text.Remove( [Text] , {"a".."z", "A".."Z"})

 

 

Thank you but this solution works


List.RemoveNulls (
List.Transform (
Text.Split ( _[Campaign Name], "-" ),
each try Number.From ( _ ) otherwise null
)
){0}

 

 

ysherriff_0-1668724064023.png

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors