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

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.

Reply
beaoliv123-_
Helper I
Helper I

Extract Last Numeric Characters and a "-"

Hi,

 

I'd like to extract the last 19 numerical characters that appear on a string of my data. These 19 characters can start with a "-" or not. So, if the "-" exists, I want to extract it too and the last 19 numbers, if not, then i only want to extract the 19 numbers. There is also the problem which is the fact that not always the interaction_id appears at the end, but in the middle of the string:

 

An example would be:

 

Data_Inside_My_Column_4164830253820475205

This_Could_Be_The_Second_lineOfMy_Data_and_-3740692547306925483

Data_Inside_My_ColumnInTheMiddle_6387632173671847831_SoThisIsComplicated

Data_Inside_My_ColumnWithSpecialCharacter_-7283782058945492094_AndThatIsIt

 

For each one of the above lines I would like to have a column with the following:

4164830253820475205

-3740692547306925483

6387632173671847831

-7283782058945492094

 

Can you help me do that on Power BI?

 

Thanks a lot

1 ACCEPTED SOLUTION
bolfri
Super User
Super User

bolfri_1-1678389121787.png

Add custom column as following:

List.First(
        List.RemoveNulls(
            List.Transform(
                Text.Split([FullString],"_"),
                each 
                    let x = try Number.FromText(_)
                    in if x[HasError] then null else _
            )
        )
    )

 

Steps:

1. Take FullString column and split it by _ into list

2. For each item in the list try to convert it into number
3. If transformations has error > give me null, else give me that value

4. Remove all nulls

5. Return fist item in the list





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
CNENFRNL
Community Champion
Community Champion

CNENFRNL_0-1678413454159.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

bolfri
Super User
Super User

bolfri_1-1678389121787.png

Add custom column as following:

List.First(
        List.RemoveNulls(
            List.Transform(
                Text.Split([FullString],"_"),
                each 
                    let x = try Number.FromText(_)
                    in if x[HasError] then null else _
            )
        )
    )

 

Steps:

1. Take FullString column and split it by _ into list

2. For each item in the list try to convert it into number
3. If transformations has error > give me null, else give me that value

4. Remove all nulls

5. Return fist item in the list





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




umanbr
Frequent Visitor

Hi ,

Use split column transformation in power query. Duplicate the column , split column by non-digit to digit and again by digit to non- digit will extract the numeric value.And then create a calculated column using below:

NewColumn =
var x=FIND("-",'Table'[text],,0)
return
IF(x=0,'Table'[numeric],CONCATENATE("-",'Table'[numeric]))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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