【实例】校验18位身份证号码的PowerQuery代码

标记不足18位的身份证号 = Table.AddColumn(去除空格, "标记不足18位的身份证号", each if Text.Length([去除空格])<>18 then "Renew" else [去除空格]),//标记出18位的身份证号码,如果不是18位的,需要更新(Renew)

计算余数 = Table.AddColumn(标记不足18位的身份证号, "计算余数", each if [标记不足18位的身份证号]="Renew" then "Renew" else Number.Mod((Number.FromText(Text.At([去除空格],0))*7+Number.FromText(Text.At([去除空格],1))*9

+Number.FromText(Text.At([去除空格],2))*10+Number.FromText(Text.At([去除空格],3))*5+Number.FromText(Text.At([去除空格],4))*8+Number.FromText(Text.At([去除空格],5))*4+Number.FromText(Text.At([去除空格],6))*2

+Number.FromText(Text.At([去除空格],7))*1+Number.FromText(Text.At([去除空格],8))*6+Number.FromText(Text.At([去除空格],9))*3+Number.FromText(Text.At([去除空格],10))*7+Number.FromText(Text.At([去除空格],11))*9

+Number.FromText(Text.At([去除空格],12))*10+Number.FromText(Text.At([去除空格],13))*5+Number.FromText(Text.At([去除空格],14))*8+Number.FromText(Text.At([去除空格],15))*4+Number.FromText(Text.At([去除空格],16))*2),11)),

校验码 = Table.AddColumn(计算余数, "校验码", each if [计算余数]="Renew" then "Renew" else if [计算余数]=0 then 1 else if [计算余数]=1 then 0 else if [计算余数]=2 then "X" else if [计算余数]=3 then 9

else if [计算余数]=4 then 8 else if [计算余数]=5 then 7 else if [计算余数]=6 then 6 else if [计算余数]=7 then 5 else if [计算余数]=8 then 4 else if [计算余数]=9 then 3 else 2),

更改的类型1 = Table.TransformColumnTypes(校验码,{{"校验码", type text}}),

比对校验码 = Table.AddColumn(更改的类型1, "比对校验码", each if[校验码]="Renew" then "Renew" else if Text.Upper(Text.At([去除空格],17))=[校验码] then "Y" else "Renew"),//不能通过校验的身份证号码标记为需更新(Renew)

你可能感兴趣的:(【实例】校验18位身份证号码的PowerQuery代码)