Forum Discussion

gauravnarchal's avatar
gauravnarchal
Post Prodigy
4 years ago
Solved

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. The Alphanumeric Field accepts values only...
  • PhilipTreacy's avatar
    4 years ago

    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"

     

     

    Regards

     

    Phil