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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.