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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
IvanS
Helper V
Helper V

Extract text after specific text string

Hi guys,

 

I am trying to get location code from the column Subject in table FACT_Tasks - example below:

 

Logic: If Subject contains (anywhere) the specific text string (AAAA or BBBB), then

- If AAAA - then take 10 characters (including AAAA)

- If BBBB - then take 12 characters (including BBBB)

 

I would prefer to have this in DAX as calculated column and not via Power Query.

 

SubjectLocation code (calculated)
Texttexttext(blank)
Task 1 - AAAA123456AAAA12345
Task Subject Name - BBBB1234567-89BBBB12345-67

 

Thank you
IvanS

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

you can change the numbers 10 and 12 to any other numbers if it is necessary for you

Screenshot_2.png

View solution in original post

6 REPLIES 6
Ksyokz23
Frequent Visitor

How about if I want to do same but this time with Power Query not with DAX 

ThxAlot
Super User
Super User

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCkmtKCmBYqVYHaBAYnG2gqGCroIjEBgaGZuYmiHEg0uTslKTSxT8EnNTgUqcgACixFzXwlIpNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Subject = _t]),

    Extracted = Table.AddColumn(Source, "Location code", each if Text.Contains([Subject], "AAAA") then Text.Range([Subject], Text.PositionOf([Subject], "AAAA"), 10) else try Text.Range([Subject], Text.PositionOf([Subject], "BBBB"), 12) otherwise null)
in
    Extracted

ThxAlot_0-1691826204404.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



Ahmedx
Super User
Super User

you can change the numbers 10 and 12 to any other numbers if it is necessary for you

Screenshot_2.png

@Ahmedx How about if I want to do same but this time with Power Query not with DAX 

Hi @Ksyokz23 ,

check the response from @ThxAlot in this thread. 

 

@IvanS It worked thank you

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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