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
neil37
Advocate I
Advocate I

Data Validation - PowerQuery

Hello, 

 

I need some assistance in PowerQuery in ensuring there are 8 digits following a hyphen (i.e., 2022-########). The data comes in as 2022-2345; 2022-354; 2022-875437, etc. I need it to be reformatted to: 2022-00002345; 2022-00000354; 2022-0875437. 

 

Essentially, I just need to add zeros on the front end of the data (after the hyphen) to ensure the data matches another source for proper modeling relationships. 

 

ActualDesired
2022-48762022-00004876
2022-4647592022-00464759
2022-1232022-00000123

 

 

Thank you!

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @neil37 ,

 

I made a pbix file myself, which you can download and view later from the attachment.

Here're the steps in detail.

1.Duplicate Actual column.

vstephenmsft_0-1665558992397.png

vstephenmsft_1-1665559015545.png

 

2.Split the duplicated column with "-".

vstephenmsft_2-1665559043979.pngvstephenmsft_3-1665559051815.pngvstephenmsft_4-1665559059836.png

 

3.Change the types of the splited columns as text.

vstephenmsft_5-1665559105707.png

 

4.Add a custom column so that the number on the right half is added to 0 and combined with the number on the left half by "-".

vstephenmsft_6-1665559189603.pngvstephenmsft_7-1665559198578.png

 

5.After the unneeded columns are removed, the result is as follows.

vstephenmsft_8-1665559253718.png

 

Hopefully, the detailed steps above and the accessories will help you.

 

 

Best Regards,

Stephen Tao

 

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

5 REPLIES 5
Anonymous
Not applicable

Hi @neil37,

 

Did @jgordon11 's reply help you? Just create a blank query and then put the codes into Advanced editor.

If it did, please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

Best Regards,

Stephen Tao

 

Hi @jgordon11  & @Anonymous , 

 

I imagine the code would work if I was starting from a blank query not connected to a specific source already? This specific task is for a source that is ingested already via an active query.  I am a bit new to this language and do not see how I add this to an active query from advanced editor (i.e., which source goes where, where column names go)

Anonymous
Not applicable

Hi @neil37 ,

 

I made a pbix file myself, which you can download and view later from the attachment.

Here're the steps in detail.

1.Duplicate Actual column.

vstephenmsft_0-1665558992397.png

vstephenmsft_1-1665559015545.png

 

2.Split the duplicated column with "-".

vstephenmsft_2-1665559043979.pngvstephenmsft_3-1665559051815.pngvstephenmsft_4-1665559059836.png

 

3.Change the types of the splited columns as text.

vstephenmsft_5-1665559105707.png

 

4.Add a custom column so that the number on the right half is added to 0 and combined with the number on the left half by "-".

vstephenmsft_6-1665559189603.pngvstephenmsft_7-1665559198578.png

 

5.After the unneeded columns are removed, the result is as follows.

vstephenmsft_8-1665559253718.png

 

Hopefully, the detailed steps above and the accessories will help you.

 

 

Best Regards,

Stephen Tao

 

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

 

 

Thank you, Stephen.  Changing the format from whole number to text was my issue after splitting via delimeter. Greatly appreciated. 

jgordon11
Resolver II
Resolver II

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText(
"i45WMjIwMtI1NDJWitVBcExQeaZm5hZKsbEA", BinaryEncoding.Base64), Compression.Deflate))),
tbl = Table.TransformColumns(Source, {{"Column1", each let ts = Text.Split(_,"-") in ts{0} & "-" & Text.PadStart(ts{1}, 8, "0")}})
in
tbl

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.