标记不足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)
网友评论
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjU0sDAwMrQ0NjCwMLIwNTE0UorVgQkbmRoAJYCCSrGxAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [身份证号码 = _t]),
标记18位的身份证号 = Table.AddColumn(Source , "标记18位的身份证号", each if Text.Length([身份证号码])=18 then "Y" else Text.Start([身份证号码],6)&"19"&Text.End([身份证号码],9)),
#"Renamed Columns1" = Table.RenameColumns(标记18位的身份证号,{{"标记18位的身份证号", "去除空格"}}),//标记出18位的身份证号码,如果不是18位的,需要更新(Renew)
计算余数 = Table.AddColumn(#"Renamed Columns1", "计算余数", each if [去除空格]="Y" then "Y" 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 fn([计算余数])),
更改的类型1 = Table.TransformColumnTypes(校验码,{{"校验码", type text}}),
#"Added Custom" = Table.AddColumn(更改的类型1, "修正后的身份证", each if [校验码]="Y" then "Y" else [去除空格]&[校验码]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"去除空格", "计算余数", "校验码"})
in
#"Removed Columns"
fn函数代码:
let
Source = (input) =>
let
values = {
{"Y", "Y"},
{0, 1},
{1, 0},
{2, "X"},
{3, 9},
{4, 8},
{5, 7},
{6, 6},
{7, 5},
{8, 4},
{9, 3},
{10, 2},
{input, "Undefined"}
},
Result = List.First(List.Select(values, each _{0}=input)){1}
in
Result
in
Source