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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
gauravnarchal
Post Prodigy
Post Prodigy

Validate & Limit Numbers and Characters using Measure

Dear All - I have a field in my data that I want to validate & Limit Numbers and Characters

 

I want to achieve the below by creating separate measures.

  1. The Alphanumeric Field accepts values only of 10 numbers and characters. No less than and more than 10. 
  2. The Alphanumeric Field accepts values between 8-12 numbers and characters. No less than 8 and more than 12. 
  3. The numeric field accepts only 12 numbers. No less than or more than 12 numbers.
  4. The Alphabets field accepts only 12 characters. No less than or more than 12 numbers.

Data - Table 1 - Column "Field"

 

Field
1234AWQ3
12345678
12345678901
132JHK87
876J9879
YTRGYGHJK
1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @gauravnarchal 

 

Download this PBIX file with the following code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNnEMDzRWitWBcEzNzC1QOJYGhhC+sZGXh7eFOZhjYW7mZWlhbgnmRIYEuUe6e3h5K8XGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Field = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Result 1", each if Text.Length([Field]) = 10 

and List.ContainsAny(Text.ToList(Text.Lower([Field])), {"a..z"})

and List.ContainsAny(Text.ToList(Text.Lower([Field])), {"0..9"})

then true else false),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Result 2", each if Text.Length([Field]) >= 8 and Text.Length([Field]) <= 12 

and List.ContainsAny(Text.ToList(Text.Lower([Field])), {"a".."z"})

and List.ContainsAny(Text.ToList(Text.Lower([Field])), {"0".."9"})

then true else false),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Result 3", each if Text.Length([Field]) = 12 then

if List.ContainsAny(Text.ToList(Text.Lower([Field])), {"a".."z"})

then false else true else false),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Result 4", each if Text.Length([Field]) = 12 then

if List.ContainsAny(Text.ToList(Text.Lower([Field])), {"0".."9"})

then false else true else false)
in
    #"Added Custom3"

 

alphanum.png

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

5 REPLIES 5
PhilipTreacy
Super User
Super User

Hi @gauravnarchal 

 

Download this PBIX file with the following code

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyNnEMDzRWitWBcEzNzC1QOJYGhhC+sZGXh7eFOZhjYW7mZWlhbgnmRIYEuUe6e3h5K8XGAgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Field = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Result 1", each if Text.Length([Field]) = 10 

and List.ContainsAny(Text.ToList(Text.Lower([Field])), {"a..z"})

and List.ContainsAny(Text.ToList(Text.Lower([Field])), {"0..9"})

then true else false),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Result 2", each if Text.Length([Field]) >= 8 and Text.Length([Field]) <= 12 

and List.ContainsAny(Text.ToList(Text.Lower([Field])), {"a".."z"})

and List.ContainsAny(Text.ToList(Text.Lower([Field])), {"0".."9"})

then true else false),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "Result 3", each if Text.Length([Field]) = 12 then

if List.ContainsAny(Text.ToList(Text.Lower([Field])), {"a".."z"})

then false else true else false),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "Result 4", each if Text.Length([Field]) = 12 then

if List.ContainsAny(Text.ToList(Text.Lower([Field])), {"0".."9"})

then false else true else false)
in
    #"Added Custom3"

 

alphanum.png

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


PhilipTreacy
Super User
Super User

Hi @gauravnarchal 

OK, but do you have separate columns for each of these types of inputs?  Or are the columns made up of mixed field types, that is, some fields in the column are Type 1 : Alphanumeric and 10 characters, and some fields are Type 4 : Letters only and must be 12 characters?

If so, how do you distinguish between the fields?  Power Query won't know which field is which type.

 

How do you want the results flagged?  A single column with all errors in it, or one error column for each different type of field?

 

Please suypply more complete sample data and an example of your expected result/output.

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi @PhilipTreacy - I want to display the result  "Single column with all errors"

 

Below is the 

FieldResult 1Result 2Result 3Result 4
1234AWQ3FALSETRUEFALSEFALSE
12345678FALSEFALSEFALSEFALSE
12345678901FALSEFALSEFALSEFALSE
132JHK87FALSETRUEFALSEFALSE
876J9879FALSETRUEFALSEFALSE
YTRGYGHJKFALSEFALSEFALSEFALSE
PhilipTreacy
Super User
Super User

Hi @gauravnarchal 

You can't restrict/prevenmt data entry like this.  The user can enter whatever they want (subject to any restriuctions in the data entry point) but PBI/Power Query/DAX can only test the data after it's been entered and flag problems.  Is that what you want?

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi @PhilipTreacy  - Yes, I want to flag all the incorrect data that is entered.

 

Thanks

Gaurav

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.