ExcelHome技术论坛

 找回密码
 免费注册

QQ登录

只需一步,快速开始

快捷登录

搜索
EH技术汇-专业的职场技能充电站 妙哉!函数段子手趣味讲函数 Excel服务器-会Excel,做管理系统 Excel Home精品图文教程库
HR薪酬管理数字化实战 Excel 2021函数公式学习大典 Excel数据透视表实战秘技 打造核心竞争力的职场宝典
300集Office 2010微视频教程 数据工作者的案头书 免费直播课集锦 ExcelHome出品 - VBA代码宝免费下载
用ChatGPT与VBA一键搞定Excel WPS表格从入门到精通 Excel VBA经典代码实践指南
查看: 556|回复: 8

[求助] 统计相同尾号

[复制链接]

TA的精华主题

TA的得分主题

发表于 2022-8-30 17:16 | 显示全部楼层 |阅读模式
统计相同尾号,m函数怎么写呢

image.png

excel1.rar

7.96 KB, 下载次数: 30

TA的精华主题

TA的得分主题

发表于 2022-8-30 19:04 来自手机 | 显示全部楼层
create temp table aa as select rowid old_rowid,* from 统计每行相同尾号的值;cli_one_dim~temp.aa~1;create temp table bb as select *,regexp2('(\d)$',数量,1) 尾数 from aaunion;create temp table cc as select *,'('||group_concat(数量)||')' 结果 from bb group by old_rowid,尾数 having(count(数量)>1);select aa.*,group_concat(cc.结果) 结果 from aa left join cc using(old_rowid) group by aa.old_rowid;
Screenshot_2022-08-30-19-01-18-365_cn.uujian.browser.jpg

TA的精华主题

TA的得分主题

发表于 2022-8-30 19:25 | 显示全部楼层
请查看附件

excel1.rar

16.76 KB, 下载次数: 16

TA的精华主题

TA的得分主题

发表于 2022-8-30 19:35 | 显示全部楼层
本帖最后由 ThxAlot 于 2022-8-30 22:03 编辑

按照mod 10的余数分一下组就行
  1. let
  2.     Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PU9LFgAhCLqL6xZj9j1Lr/tfYwKzDY+AUNeS3CWJ6oHcDlSQBxNkIDBlpxOOmLp2XyToofUx2kPLcNXAPgAYdZQVr8UI6ApNy/s1YowblWn3zYULWe9ShhnafDN2c+d3o0WGZ/c4Rfb+AQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t, Column4 = _t, Column5 = _t, Column6 = _t, Column7 = _t, Column8 = _t, Column9 = _t]),
  3.     #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}, {"Column4", Int64.Type}, {"Column5", Int64.Type}, {"Column6", Int64.Type}, {"Column7", Int64.Type}, {"Column8", Int64.Type}, {"Column9", Int64.Type}}),

  4.     #"Grouped by Mod" = Table.AddColumn(#"Changed Type", "Grp",
  5.         each let
  6.             grp = List.Accumulate(Record.ToList(_), List.Repeat({{}},10), (s,c) => let n = Number.Mod(c, 10) in List.ReplaceRange(s, n, 1, {s{n}&{c}})),
  7.             pairs = List.Select(grp, each List.Count(_)>=2)
  8.         in Text.Combine(List.Transform(pairs, each "(" & Text.Combine(List.Transform(_, Text.From),",") & ")"), ",")
  9.     )
  10. in
  11.     #"Grouped by Mod"
复制代码
image.png

TA的精华主题

TA的得分主题

 楼主| 发表于 2022-8-31 08:14 | 显示全部楼层
感谢楼上的几位大佬,太牛逼了

TA的精华主题

TA的得分主题

发表于 2022-9-3 18:46 | 显示全部楼层
List.Accumulate还不太会用,借用Table.Group的第五参数做分组
  1. let
  2.     源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
  3.     自定义1 =
  4.         Table.AddColumn(
  5.             源,
  6.             "q",
  7.             each
  8.                 let
  9.                     t =
  10.                         Table.Group(
  11.                             Table.FromValue( Record.ToList( _ ) ),
  12.                             "Value",
  13.                             { "q", (x)=> "(" & Text.Combine( List.Transform( x[Value] , Text.From ), ", " ) & ")" },
  14.                             1,
  15.                             (x,y)=> Number.Mod( x, 10 ) - Number.Mod( y, 10 )
  16.                         )
  17.                 in
  18.                     Text.Combine( List.Select( t[q], (x)=> Text.Contains( x, "," ) ), " " )
  19.         )
  20. in
  21.     自定义1
复制代码

TA的精华主题

TA的得分主题

发表于 2022-9-4 21:15 | 显示全部楼层
(x,y)=> Number.Mod( x, 10 ) - Number.Mod( y, 10 )这个第五参数没看懂,还请大佬指导一下
                        

TA的精华主题

TA的得分主题

发表于 2022-9-5 22:39 | 显示全部楼层
let
    源 = Excel.CurrentWorkbook(){[Name="表1"]}[Content],
    自定义1 = Table.ToList(源,(x)=>List.Generate(
                                                ()=>0,each _<10,each _+1,each List.Select(
                                                                                          x,(y)=>Text.End(Text.From(y),1)=Text.From(_)
                                                                              )
                                )
                ),
    自定义2 = List.Transform( 自定义1,each Text.Combine(
                                                        List.RemoveNulls(
                                                                        List.Transform(
                                                                                        _,(x)=>if List.Count(x)<2
                                                                                                then null
                                                                                                else
                                                                                                "(" &Text.Combine(
                                                                                                                List.Transform(x,(y)=>Text.From(y)),","
                                                                                                )&")"
                                                                        )
                                                        ),","
                                            )
                            ),
    自定义3 = Table.FromColumns(Table.ToColumns(源) &{自定义2})
in
    自定义3

TA的精华主题

TA的得分主题

 楼主| 发表于 2023-5-3 20:52 | 显示全部楼层
您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

手机版|关于我们|联系我们|ExcelHome

GMT+8, 2024-4-30 17:46 , Processed in 0.040928 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 1999-2023 Wooffice Inc.

沪公网安备 31011702000001号 沪ICP备11019229号-2

本论坛言论纯属发表者个人意见,任何违反国家相关法律的言论,本站将协助国家相关部门追究发言者责任!     本站特聘法律顾问:李志群律师

快速回复 返回顶部 返回列表