Excel 计算两个日期之间的唯一 ID + 每个 ID 的另一列的不同计数

Excel count Unique ID's between two dates + a distinct count of another column for each ID

我正在为 Excel 公式苦苦挣扎。我正在尝试计算两个日期之间唯一 ID 的数量(我有该公式),但我还想计算两个日期之间符合条件的每个唯一 ID 的 SignUpRoles。我正在使用 O365。

以下是我在 K10:14

中捕获 UserId 计数的方式
=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=K5,IF(Weartime13[RecordDate]<=J5,MATCH(Weartime13[UserId],Weartime13[UserId],0))),ROW(Weartime13[UserId])-ROW(A5)+1),1))

这是我正在使用的工作表:RDS_Report

截图: RDS Report Screenshot

所以我添加另一个 'if' 的意思是,在 L14 中(例如)你会

=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=L9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(A5)+1),1))

在下一列将更改为 M9 和 N9:

=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=M9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(A5)+1),1))

=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=N9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(A5)+1),1))

我已经填写了最后一行:

编辑

正如@JosWoolley 所指出的,结构化引用比 row(A5) 更可取。我会建议:

=SUM(IF(FREQUENCY(IF(Weartime13[RecordDate]>=O5,IF(Weartime13[RecordDate]<=J5,IF(Weartime13[SignUpRole]=L9,MATCH(Weartime13[UserId],Weartime13[UserId],0)))),ROW(Weartime13[UserId])-ROW(Weartime13[#Headers])),1))

但是,如果您想要跨过这些公式以便 L9 自动更改为 M9 和 N9 但它仍然引用相同的 table 列怎么办?我必须查一下这个,答案是:

=SUM(IF(FREQUENCY(IF(Weartime13[[RecordDate]:[RecordDate]]>=$O5,IF(Weartime13[[RecordDate]:[RecordDate]]<=$J5,IF(Weartime13[[SignUpRole]:[SignUpRole]]=L9,MATCH(Weartime13[[UserId]:[UserId]],Weartime13[[UserId]:[UserId]],0)))),ROW(Weartime13[[UserId]:[UserId]])-ROW(Weartime13[#Headers])),1))

最后一行使用计数和过滤器的公式为

=COUNT(UNIQUE(FILTER(Weartime13[UserId],(Weartime13[RecordDate]<=J5)*(Weartime13[RecordDate]>=O5))))

总数和

=COUNT(UNIQUE(FILTER(Weartime13[[UserId]:[UserId]],(Weartime13[[RecordDate]:[RecordDate]]<=$J5)*(Weartime13[[RecordDate]:[RecordDate]]>=$O5)*(Weartime13[[SignUpRole]:[SignUpRole]]=L9))))

拉过 SignUpRole 细分,假设 UserId 是数字。

但是,如果您想要一个可以在整个日期和角色范围内都被拉下和跨越的单一公式怎么办?这可以安排如下:

=COUNT(UNIQUE(FILTER(Weartime13[UserId],(Weartime13[RecordDate]<=J)*(Weartime13[RecordDate]>=INDEX($K:$O,ROW()-ROW(:))))))

总数和

=COUNT(UNIQUE(FILTER(Weartime13[[UserId]:[UserId]],(Weartime13[[RecordDate]:[RecordDate]]<=$J)*(Weartime13[[RecordDate]:[RecordDate]]>=INDEX($K:$O,ROW()-ROW(:)))*(Weartime13[[SignUpRole]:[SignUpRole]]=L))))

对于角色列。

有没有更简单的方法来完成这一切?也许使用 pivot tables 或者 power query,但这将是一个单独的答案:-)