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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Sathyabalan
Frequent Visitor

Power BI Service - Using MID and FIND, tried to extract 5 letters from a Device Name

Hi All,

Good Day!

I am trying to extract 5 letters from a Device Names Column to a new column in the Power BI Service, wherever the Device Names have letter H then from H, 5 letters should be extracted but I am getting below error while running the below DAX Function, some device names wont have letter 'H' that need to be ignored.

 

Code = MID(Device[Device Name],FIND("H",'Device[Device Name],1),5)

getting below error

The following syntax error occurred during parsing: Invalid token, Line 1, Offset 34,

 

Device Names

W-L-H0000-S

AAA-H3433-W

L-SS-0908000

AE-EEELLOE90

S-E-H00e0-dd

 

After Extraction the new column should be like as below

H0000

H3433

0 or null

0

H00E0

 

Best Regards

Sathya

3 ACCEPTED SOLUTIONS
ThxAlot
Super User
Super User

DAX wasn't designed for such tasks; use PQ to achieve it.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JYwxCsAgEAT/cnUWTM4ilhYHQg4ELUwidub/X4gx2yw7DFsrFSiCGUGmtlTy3iOwZUaZW5EzjDP7UH5BICKqUdwPMuR7eAx6n+C8boR1Y8RjtkVKiVp7AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Device Names" = _t]),

    #"Device Name" = Table.AddColumn(Source, "Device Name", each let l = Text.Split([Device Names], "-"), pos = List.PositionOf(l, "h", Occurrence.First, (x,y) => Text.Length(x) = 5 and Text.StartsWith(x, y, Comparer.OrdinalIgnoreCase)) in try l{pos} otherwise null)
in
    #"Device Name"

 

ThxAlot_2-1717963348113.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


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


)



View solution in original post

v-kaiyue-msft
Community Support
Community Support

Hi @Sathyabalan ,

 

Your solution is great, @ThxAlot . It worked like a charm! Here I have another idea in mind, and I would like to share it for reference. 

 

Create a calculated column.

NewColumn = 
VAR startPos = SEARCH("H", 'Device'[Device Names], 1, LEN('Device'[Device Names]))
VAR result = IF(startPos > 0, MID('Device'[Device Names], startPos, 5), BLANK())
RETURN result

 

vkaiyuemsft_0-1717984388764.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi @Sathyabalan ,

 

You can try this.

NewColumn = 
VAR startPos = SEARCH("H", 'Device'[Device Names], 1, 0)
VAR result = IF(startPos > 0, MID('Device'[Device Names], startPos, 5), "0")
RETURN result

vkaiyuemsft_0-1718089067957.png

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

7 REPLIES 7
v-kaiyue-msft
Community Support
Community Support

Hi @Sathyabalan ,

 

Your solution is great, @ThxAlot . It worked like a charm! Here I have another idea in mind, and I would like to share it for reference. 

 

Create a calculated column.

NewColumn = 
VAR startPos = SEARCH("H", 'Device'[Device Names], 1, LEN('Device'[Device Names]))
VAR result = IF(startPos > 0, MID('Device'[Device Names], startPos, 5), BLANK())
RETURN result

 

vkaiyuemsft_0-1717984388764.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-kaiyue-msft 

yes, it worked like a charm but wherever the H is not there it extracts the last letter of the Device Name instead of showing 0 or null, if any workaround, would be greatly appreciated

 

Sathyabalan_0-1718039678573.png

 

Best Regards

Sathya

Hi @Sathyabalan ,

 

You can try this.

NewColumn = 
VAR startPos = SEARCH("H", 'Device'[Device Names], 1, 0)
VAR result = IF(startPos > 0, MID('Device'[Device Names], startPos, 5), "0")
RETURN result

vkaiyuemsft_0-1718089067957.png

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-kaiyue-msft ,

 

It worked like a charm! Thank You Very Much

I'm afraid SEARCH() doesn't work when it comes to more than one occurrences of "H".

ThxAlot_0-1717994533099.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


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


)



ThxAlot
Super User
Super User

DAX wasn't designed for such tasks; use PQ to achieve it.

 

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("JYwxCsAgEAT/cnUWTM4ilhYHQg4ELUwidub/X4gx2yw7DFsrFSiCGUGmtlTy3iOwZUaZW5EzjDP7UH5BICKqUdwPMuR7eAx6n+C8boR1Y8RjtkVKiVp7AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Device Names" = _t]),

    #"Device Name" = Table.AddColumn(Source, "Device Name", each let l = Text.Split([Device Names], "-"), pos = List.PositionOf(l, "h", Occurrence.First, (x,y) => Text.Length(x) = 5 and Text.StartsWith(x, y, Comparer.OrdinalIgnoreCase)) in try l{pos} otherwise null)
in
    #"Device Name"

 

ThxAlot_2-1717963348113.png



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


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


)



Hi @ThxAlot Thank very much for your prompt reply and trying to help, but I have little knowledge on the Power Query in Power BI Serivice, Are you saying that I need to create a measure with your query in the PQ or Additional Column or Table?, Not sure how to insert your PQ into Power Bi Service, I really appreciated your efforts to make a PQ for me, If you guide me a little then I can make it

Helpful resources

Announcements
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Top Solution Authors