Good afternoon,
I'm new to M and just started to scratch the surface in the advanced editor. The Excel formula below let's me extract a check digit from a UPC. I need this so I can have a unique lookup value for my products. I've have replicated it in M but it looks ugly.
=MOD(10-MOD((MID([UPC],12,1)+MID([UPC],10,1)+MID([UPC],8,1)+MID([UPC],6,1)+MID([UPC],4,1)+MID([UPC],2,1))*3+MID([UPC],11,1)+MID([UPC],9,1)+MID([UPC],7,1)+MID([UPC],5,1)+MID([UPC],3,1)+MID([UPC],1,1),10),10)
Here is the code I am using in M. It is my first pass but it works. Anyone have an suggestions for making it cleaner?
Number.Mod ( 10 -
Number.Mod (
( Number.FromText ( Text.Range( [UPC 12 digit] , 12 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (12 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 10 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (10 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 8 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (8 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 6 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (6 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 4 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (4 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 2 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (2 - 1) , 1} ) ) ) )* 3 +
Number.FromText (Text.Range( [UPC 12 digit] , 11 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (11 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 9 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (9 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 7 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (7 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 5 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (5 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 3 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (3 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 1 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (1 - 1) , 1} ) ) ) , 10 ) , 10 )
I'm new to M and just started to scratch the surface in the advanced editor. The Excel formula below let's me extract a check digit from a UPC. I need this so I can have a unique lookup value for my products. I've have replicated it in M but it looks ugly.
=MOD(10-MOD((MID([UPC],12,1)+MID([UPC],10,1)+MID([UPC],8,1)+MID([UPC],6,1)+MID([UPC],4,1)+MID([UPC],2,1))*3+MID([UPC],11,1)+MID([UPC],9,1)+MID([UPC],7,1)+MID([UPC],5,1)+MID([UPC],3,1)+MID([UPC],1,1),10),10)
Here is the code I am using in M. It is my first pass but it works. Anyone have an suggestions for making it cleaner?
Number.Mod ( 10 -
Number.Mod (
( Number.FromText ( Text.Range( [UPC 12 digit] , 12 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (12 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 10 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (10 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 8 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (8 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 6 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (6 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 4 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (4 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 2 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (2 - 1) , 1} ) ) ) )* 3 +
Number.FromText (Text.Range( [UPC 12 digit] , 11 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (11 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 9 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (9 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 7 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (7 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 5 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (5 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 3 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (3 - 1) , 1} ) ) ) +
Number.FromText (Text.Range( [UPC 12 digit] , 1 - 1 , List.Min( {Text.Length ([UPC 12 digit] ) - (1 - 1) , 1} ) ) ) , 10 ) , 10 )