Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hello,
I have two datasets I am merging using an ID number. The ID number comes from an external source, and we manually enter it into our system. Unfortunately, it is rarely entered in the correct format, making it impossible to match records. I manually go into our system to fix them, but I am hoping for a solution that doesn't require me to. The proper format is "023459-000000-MS-01". The first 6 digits never change, and always have the leading zero. The next 6 digits are unique, and the "-MS-01" doesn't change.
Below is an example of how the ID number has been entered, with the corresponding correctly formatted ID number.
Thank you!
| Raw ID Number | Properly Formatted ID Number |
| 023459000208 | 023459-000208-MS-01 |
| 023459-000235-MS-01 | 023459-000235-MS-01 |
| 23459-00125-MS-01 | 023459-00125-MS-01 |
| 23459000447 | 023459-000447-MS-01 |
| 23459000302-MS-01 | 023459-000302-MS-01 |
| 023459--000375-MS-01 | 023459-000375-MS-01 |
| 023459000170-MS-01 | 023459-000170-MS-01 |
| 023459-000288-ms-01 | 023459-000288-MS-01 |
| 023459-00260 | 023459-000260-MS-01 |
| 23459-00120-ms-01 | 023459-000120-MS-01 |
Solved! Go to Solution.
You can use this formula in the Add Custom Column dialog:
= [a=Text.Upper([Raw ID Number]),
b=Text.PositionOf(a,"23459"),
c=Text.RemoveRange(a,0,7-b),
d=Text.Replace(c,"MS-01",""),
e=Text.Trim(d,"-"),
f=Number.ToText(
Number.From(e),"""023459-""000000""-MS-01""")][f]
You can use this formula in the Add Custom Column dialog:
= [a=Text.Upper([Raw ID Number]),
b=Text.PositionOf(a,"23459"),
c=Text.RemoveRange(a,0,7-b),
d=Text.Replace(c,"MS-01",""),
e=Text.Trim(d,"-"),
f=Number.ToText(
Number.From(e),"""023459-""000000""-MS-01""")][f]
Hi @memote1,
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you.
Hi @memote1, check this:
Output
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjAyNjG1NDAwMDKwUIrVgQnogkSMTXV9g3UNDMHiMGFDIwxRoFoTE3MUvrGBEZIqqJkgQ43NTTEkgMKG5gaY6kFusLDQzS3GEDcyM0BzlAFMWSwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Raw ID Number" = _t]),
Ad_CorrectID = Table.AddColumn(Source, "Correct ID", each
[ col = [Raw ID Number],
a = Text.PositionOf(col, "9") +1,
b = Text.Start(col, a),
start = Text.PadStart(b, 6, "0"),
mid = Text.PadStart(Text.BeforeDelimiter(Text.TrimStart(Text.RemoveRange(col, 0, Text.Length(b)), {"-"}), "-"), 6, "0"),
result = Text.Combine({start, mid, "MS-01"}, "-")
][result], type text)
in
Ad_CorrectID
You can use Fuzzy merge
Hi @memote1 , Add a custom column to generate the corrected format
Text.PadStart(Text.Middle(Text.Remove(Text.Lower([Raw ID Number]), "-ms-01"), 6), 6, "0") & "-" &
Text.PadStart(Text.Middle(Text.Remove(Text.Lower([Raw ID Number]), "-ms-01"), 6, Text.Length(Text.Remove(Text.Lower([Raw ID Number]), "-ms-01")) - 6), 6, "0") &
"-MS-01"
If this post helped please do give a kudos and accept this as a solution
Thanks In Advance
Hi @memote1,
Thanks for posting your query in Microsoft fabric community forum.
I have reproduced your scenario and successfully transformed the data using Power Query in Power BI Desktop. Below are the detailed steps I followed, along with the expected output. I am also attaching a screenshot and PBIX file for your reference.
Step 1: I used the following sample data to simulate your scenario:
|
Raw ID Number |
|
023459000208 |
|
023459-000235-MS-01 |
|
23459-00125-MS-01 |
|
23459000447 |
|
23459000302-MS-01 |
|
023459--000375-MS-01 |
|
023459000170-MS-01 |
|
023459-000288-ms-01 |
|
023459-00260 |
|
23459-00120-ms-01 |
Step 2: Load Data into Power Query
Step 3: Convert All IDs to Uppercase
Step 4: Extract Only Numeric Digits
CODE:
CopyEdit
Text.Select([Raw ID Number], {"0".."9"})
Step 5: Extract the Unique 6-Digit Part
CopyEdit
Text.Middle([NumericOnly], 6)
Step 6: Ensure 6 Digits with Leading Zeros
CODE:
CopyEdit
Text.PadStart([UniquePart], 6, "0")
Step 7: Construct the Final ID Format
CODE:
CopyEdit
"023459-" & [PaddedUniquePart] & "-MS-01"
Step 8: Finalizing the Data
Output:
If this helps, then please Accept it as a solution and dropping a "Kudos" so other members can find it more easily.
Thank you.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.