分组数据时仅获得相关行

发布于 2025-01-29 21:39:43 字数 2017 浏览 1 评论 0原文

我有参考的数据,我希望分组和提取最高和最常见的值,同时保留相关参考文献:

“

绿色的桌子是我到目前为止所取得的成就:

m代码:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CAS", type text}, {"Type ", type text}, {"Value ", type text}, {"Ref", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"CAS", "Type "}, {{"Value Most Common", each List.Mode([#"Value "]), type nullable text}, {"Ref", each Text.Combine([Ref], ", "), type nullable text}, {"Value Lowest", each List.Max([#"Value "]), type nullable text}})
in
    #"Grouped Rows"

我遇到的问题是如何最好地将参考文献分解为最常见和最低的值。尽管进行了多次尝试,但我只是做对了。问题之所以出现,是因为通过按值分裂列,引用链接了,但是从输入来判断这必须是可能的。我怀疑在分组之前我需要一些额外的步骤。

此外,我不确定如何使用分组来捕获最常见值之间有联系的模式。 list.modes返回列表,但我再次遇到错误。目前,我只返回单个模式。这是一个较少的问题,但与第3行所需的第3行一样,这是一个很好的问题。

Data: 
CAS Type    Value   Ref
77-92-9 NOAEL   1200    WebNet
77-92-9 NOAEL   1200    Wiki
77-92-9 NOAEL   4000    ECHA
77-92-9 DNEL    500 RB Data
25265-71-8  DNEL    51  WebNet
25265-71-8  DNEL    24  ECHA
25265-71-8  DNEL    24  ECHA
25265-71-8  DNEL    50  ECHA
25265-71-8  DNEL    50  ECHA
25265-71-8  DNEL    10  ECHA
25265-71-8  NOAEL   200     OECD
106-24-1    DNEL    13.75   ECHA
106-24-1    DNEL    13.75   ECHA
106-24-1    NOAEL   300     RIFM
106-24-1    NOAEL   550     ECHA
106-24-1    NOAEL   50  SAM
106-24-1    NOAEL   50  RIFM
128-37-0    NOAEL   25  ECHA
128-37-0    NOAEL   25  ECHA
128-37-0    NOAEL   25  SAM
128-37-0    ADI 0.3     MMMD
128-37-0    ADI 0.25    JECFA
128-37-0    ADI 0.25    EFSA
60-12-8 DNEL    5.1     ECHA
60-12-8 NOAEL   385     RIFM

I have data with reference that I wish to group and extract the highest and most common values whilst retaining the relevant references:

enter image description here

The table in green is what I have achieved so far:

enter image description here

M Code:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CAS", type text}, {"Type ", type text}, {"Value ", type text}, {"Ref", type text}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"CAS", "Type "}, {{"Value Most Common", each List.Mode([#"Value "]), type nullable text}, {"Ref", each Text.Combine([Ref], ", "), type nullable text}, {"Value Lowest", each List.Max([#"Value "]), type nullable text}})
in
    #"Grouped Rows"

The problem I am having is how best to separate out the References for The Most common and Lowest values. Despite multiple attempts, I just can't get it right. The problem arises because by Splitting columns by Value the references become linked however judging from the input this must be possible. I suspect I need some additional step before grouping.

Additionally, I am unsure how to use grouping to capture Modes where there is a tie between most common values. List.Modes returns a List but again I a running into errors. Currently, I only return the single mode. This is a lesser issue but would be nice as with 24,50 in row 3 of desired.

Data: 
CAS Type    Value   Ref
77-92-9 NOAEL   1200    WebNet
77-92-9 NOAEL   1200    Wiki
77-92-9 NOAEL   4000    ECHA
77-92-9 DNEL    500 RB Data
25265-71-8  DNEL    51  WebNet
25265-71-8  DNEL    24  ECHA
25265-71-8  DNEL    24  ECHA
25265-71-8  DNEL    50  ECHA
25265-71-8  DNEL    50  ECHA
25265-71-8  DNEL    10  ECHA
25265-71-8  NOAEL   200     OECD
106-24-1    DNEL    13.75   ECHA
106-24-1    DNEL    13.75   ECHA
106-24-1    NOAEL   300     RIFM
106-24-1    NOAEL   550     ECHA
106-24-1    NOAEL   50  SAM
106-24-1    NOAEL   50  RIFM
128-37-0    NOAEL   25  ECHA
128-37-0    NOAEL   25  ECHA
128-37-0    NOAEL   25  SAM
128-37-0    ADI 0.3     MMMD
128-37-0    ADI 0.25    JECFA
128-37-0    ADI 0.25    EFSA
60-12-8 DNEL    5.1     ECHA
60-12-8 NOAEL   385     RIFM

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你在看孤独的风景 2025-02-05 21:39:43

这一切都在分组中:

编辑为多种模式,如您的编辑

let
    Source = Excel.CurrentWorkbook(){[Name="Input"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CAS", type text}, {"Type", type text}, {"Value", type number}, {"Ref", type text}}),

    #"Grouped Rows" = Table.Group(#"Changed Type", {"CAS", "Type"}, {
        {"Most Common", each Text.Combine(List.Transform(List.Modes([Value]), each Text.From(_)),", "), type text},
        {"Ref", (t)=>Text.Combine(List.Distinct(Table.SelectRows(t, each List.Contains(List.Modes(t[Value]),[Value]))[Ref]),", "), type text},
        {"Max", each List.Max([Value]), type number},
        {"Ref2", (t)=>Text.Combine(List.Distinct(Table.SelectRows(t, each [Value]=List.Max(t[Value]))[Ref]),", "), type text}
       })

in
    #"Grouped Rows"

数据更改为具有多种模式的Demo多refs的数据

It's all in the grouping:

Edited to account for multiple modes as seen after your edit

let
    Source = Excel.CurrentWorkbook(){[Name="Input"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"CAS", type text}, {"Type", type text}, {"Value", type number}, {"Ref", type text}}),

    #"Grouped Rows" = Table.Group(#"Changed Type", {"CAS", "Type"}, {
        {"Most Common", each Text.Combine(List.Transform(List.Modes([Value]), each Text.From(_)),", "), type text},
        {"Ref", (t)=>Text.Combine(List.Distinct(Table.SelectRows(t, each List.Contains(List.Modes(t[Value]),[Value]))[Ref]),", "), type text},
        {"Max", each List.Max([Value]), type number},
        {"Ref2", (t)=>Text.Combine(List.Distinct(Table.SelectRows(t, each [Value]=List.Max(t[Value]))[Ref]),", "), type text}
       })

in
    #"Grouped Rows"

Data changed to demo multiple Refs with Multiple Mode
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文