我的数据看起来像这样:
User PaymentType Month
-----------------------------------
A Early Payment 1
A Early Payment 2
A Early Payment 3
A Outstanding 4
A Outstanding 5
A Outstanding 6
B Early Payment 1
B Early Payment 2
B Early Payment 3
B Outstanding 4
B Outstanding 5
B Outstanding 6
如何为每个用户创建仅返回“Outstanding”PaymentType
的最小月份的计算,然后可以将其作为数据中的新列放入?我需要跟踪每个用户第一个“杰出”PaymentType
的时间。
答案 0 :(得分:2)
{ FIXED [User] : MIN(IIF([Payment Type] = 'Outstanding', [Month], NULL)) } = [Month]
如果用户是未付款的第一个月,那么这将为您提供一个真实的列,否则为false。数据如下所示:
+------+---------------+-------+---------------------------+
| User | PaymentType | Month | First Outstanding Payment |
+------+---------------+-------+---------------------------+
| A | Early Payment | 1 | F |
| A | Early Payment | 2 | F |
| A | Early Payment | 3 | F |
| A | Outstanding | 4 | T |
| A | Outstanding | 5 | F |
| A | Outstanding | 6 | F |
| B | Early Payment | 1 | F |
| B | Early Payment | 2 | F |
| B | Early Payment | 3 | F |
| B | Outstanding | 4 | T |
| B | Outstanding | 5 | F |
| B | Outstanding | 6 | F |
+------+---------------+-------+---------------------------+
请注意,这是针对您提供给我们的确切数据。例如,如果您的月份是日期字段(而不仅仅是数字),或者您为数据添加了多年,或者每月有多笔付款,则必须调整此公式。但是,这为您提供了如何计算您正在寻找的内容的基本概念,并且应该不难更新计算以满足您的需求。
如果bool不是您想要的,您可以取出条件,让该字段保存第一笔未付款的月份数。
{ FIXED [User] : MIN(IIF([Payment Type] = 'Outstanding', [Month], NULL)) }
在这种情况下,您的数据将如下所示:
+------+---------------+-------+---------------------------+
| User | PaymentType | Month | First Outstanding Payment |
+------+---------------+-------+---------------------------+
| A | Early Payment | 1 | 4 |
| A | Early Payment | 2 | 4 |
| A | Early Payment | 3 | 4 |
| A | Outstanding | 4 | 4 |
| A | Outstanding | 5 | 4 |
| A | Outstanding | 6 | 4 |
| B | Early Payment | 1 | 4 |
| B | Early Payment | 2 | 4 |
| B | Early Payment | 3 | 4 |
| B | Outstanding | 4 | 4 |
| B | Outstanding | 5 | 4 |
| B | Outstanding | 6 | 4 |
+------+---------------+-------+---------------------------+