如果另一列中的前一行相同,则累积总和

发布于 2025-01-17 05:54:10 字数 3014 浏览 3 评论 0原文

我正在尝试做一些在 Excel 中简单的事情,但我需要将其添加到我的查询中。如果名称列等于前一行,我试图在一列中的新时间值列中创建累积和。以下前后示例

数据输入表

ID时间
A2
B3
C1
D0.5
E1
E3
E5
F2
G3
G4
H1

查询后表

ID时间启动前
A20
B30
C10
D0.50
E10
E31
E54
F20
G30
G43
H10

基本上,如果列 ID 等于其上方的行,则将时间与自身上方的 BeforeStart 行相加,如果不相等,则为 0。

I'm trying to do something that is simple in excel but I need it to be added in my query. I am trying to create a cumulative sum in a new column of time values in one column if a name column equals a previous row. Example of before and after below

Data Input Table

IDTime
A2
B3
C1
D0.5
E1
E3
E5
F2
G3
G4
H1

Table After Query

IDTimeBeforeStart
A20
B30
C10
D0.50
E10
E31
E54
F20
G30
G43
H10

Basically if column ID equals the row above itself then sum the time and BeforeStart rows above itself, if it doesn't then it is 0.

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

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

发布评论

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

评论(2

拥醉 2025-01-24 05:54:10

在 powerquery 中,尝试将 Table2 替换为源数据表的名称

let 
  xFunction = (xTable as table) as table => let
  #"Added Index" = Table.AddIndexColumn(xTable, "Index", 1, 1, Int64.Type),
  #"Added Custom" = Table.AddColumn(#"Added Index", "Running Total", each List.Sum(List.FirstN(#"Added Index"[Time],[Index]-1)))
  in  #"Added Custom",

Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Time", type number}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"data", each  xFunction(_), type table }}),
#"Expanded data" = Table.ExpandTableColumn(#"Grouped Rows", "data", {"Time", "Running Total"}, {"Time", "Running Total"})
in #"Expanded data"

在此处输入图像描述

In powerquery, try below and replace Table2 with the name of your source data table

let 
  xFunction = (xTable as table) as table => let
  #"Added Index" = Table.AddIndexColumn(xTable, "Index", 1, 1, Int64.Type),
  #"Added Custom" = Table.AddColumn(#"Added Index", "Running Total", each List.Sum(List.FirstN(#"Added Index"[Time],[Index]-1)))
  in  #"Added Custom",

Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Time", type number}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"data", each  xFunction(_), type table }}),
#"Expanded data" = Table.ExpandTableColumn(#"Grouped Rows", "data", {"Time", "Running Total"}, {"Time", "Running Total"})
in #"Expanded data"

enter image description here

穿透光 2025-01-24 05:54:10

试试这个功能:

=IF(COUNTIF($A2:$A$2,$A2)=1,0,SUMPRODUCT((A2:$A$2=A2)*B2:$B$2)-B2)

Try this function:

=IF(COUNTIF($A2:$A$2,$A2)=1,0,SUMPRODUCT((A2:$A$2=A2)*B2:$B$2)-B2)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文