不同场景同列日差您好,我对以下不同场景有疑问。 非常感谢任何帮助!
场景A :我想添加最后一列,计算该用户ID,与第一的网络到第一的预定日期。 如果他在预订操作之前没有网络操作,则将其留空。 有人可以帮助我使用该函数而不是 jsl 来了解公式应该是什么样子吗?
| 用户身份 | 行动 | 日期 | 首次上网日期至首次预订日期 |
| 2523 | 网络 | 2018-05-06 | 22 |
| 2523 | 网络 | 2018-05-16 | 22 |
| 2523 | 预订 | 2018-05-28 | 22 |
| 2523 | 预订 | 2018-06-08 | 22 |
| 2523 | 网络 | 2018-07-08 | 22 |
| 2523 | 预订 | 2018-08-08 | 22 |
场景B :根据上表,我想计算另一个如下表,其中包含每个用户 ID 之间的天差首次网络操作日期“预订前”到每个预订日期。 根据逻辑,以上表作为输入的理想结果将如下所示,该用户 ID 有 3 个日差实例。 与场景 A 相同,我们仅考虑网络在预订之前的情况。
| 用户身份 | 实例 | 计算 |
| 2523 | 22 | 5/28 减 5/6 |
| 2523 | 33 | 6/8 减 5/6 |
| 2523 | 31 | 8/8 减 7/8 |
谢谢你!
质量和工艺工程回复:不同场景同一栏目日差有用! 非常感谢格奥尔格! 将从Matrix和Loc的链接中学习。 非常感谢您的帮助。回复:不同场景同一栏目日差你好@乔安,很抱歉,这不是提供全方位服务的平台,但如果我们能为您提供支持,我们很高兴。 因此,如果您想学习,请参阅有关此处使用的函数的在线文档。
例如 loc 为您提供某些值的向量索引:
定位函数 (jmp.com)
请参阅下面的脚本了解这两种情况。 场景 B 非常相似......
如果您想要获得与您所描述的场景 B 完全相同的表格,您可以删除公式(保留当时的值),然后选择“公式 B”列中的缺失值并将其删除。
BR
names default to here(1);
// create the example table
New Table( "20210404_user_web_booking_matrixexample",
Add Rows( 12 ),
Compress File When Saved( 1 ),
New Column( "userID",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values(
[2523, 2523, 2523, 2523, 2523, 2523, 2540, 2540, 2540, 2540, 2540, 2540]
),
Set Display Width( 66 )
),
New Column( "action",
Character( 16 ),
"Nominal",
Set Values(
{"web", "web", "booking", "booking", "web", "booking", "web", "web",
"booking", "booking", "web", "booking"}
),
Set Display Width( 73 )
),
New Column( "date",
Numeric,
"Continuous",
Format( "y/m/d", 12 ),
Input Format( "y/m/d" ),
Set Values(
[3608409600, 3609273600, 3610310400, 3611260800, 3613852800, 3616531200,
3647462400, 3647548800, 3647635200, 3647721600, 3647808000, 3647894400]
),
Set Display Width( 92 )
),
New Column( "first web date to first booking date",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [22, 22, 22, 22, 22, 22, ., ., ., ., ., .] ),
Set Display Width( 150 )
),
New Column( "formula_A",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula(
Names Default To Here( 1 );
// convert columns to vectors
dat_vec = :date << get values;
web_vec = :action << get values;
user_vec = :userID << get values;
// get a vector with subscripts of current userID
user_index = user_vec == :userID[Row()];
// get a vctor with subscripts where action=web
web_index = Matrix(
Substitute( :action << get values, "web", 1, "booking", 0 )
);
// get a vector with dates for current userID and action=web
web_dat = dat_vec[Loc( user_index & web_index )];
// the same for booking (actually not web)
booking_dat = dat_vec[Loc( user_index & !web_index )];
// calculate minimum of both date vectors and subtract
(Minimum( booking_dat ) - Minimum( web_dat )) / (3600 * 24);
),
Set Display Width( 146 )
),
New Column( "formula_B",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula(
Names Default To Here( 1 );
dat_vec = :date << get values;
web_vec = :action << get values;
user_vec = :userID << get values;
user_index = user_vec == :userID[Row()];
web_index = Matrix(
Substitute( :action << get values, "web", 1, "booking", 0 )
);
web_dat = dat_vec[Loc( user_index & web_index )];
booking_dat = dat_vec[Loc( user_index & !web_index )];
// when current action is booking, then subtract minimum web date, otherwise keep empty, and divide seconds by seconds of day
If( :action == "booking", :date - Minimum( web_dat ), . ) / (3600 * 24);
),
Set Selected
)
);回复:不同场景同一栏目日差谢谢格奥尔格! 有用。 你能向我解释一下这个脚本背后的逻辑吗? 我对 Matrix 和 Loc 不太熟悉。
您是否有针对场景 2 的解决方案?
谢谢你!回复:不同场景同一栏目日差谢谢蒂埃里! 结果看起来不错! 您能向我解释一下 Transaction ID 的用途吗? 我不明白逻辑/公式。
你有B场景的解决方案吗? 在场景 B 中,第二次预订很重要。
谢谢你!回复:不同场景同一栏目日差我认为以下公式适用于场景 A:
它尚未优化,但可能会向您展示如何完成此类操作。
它在公式中逐步使用一些简单的 jsl。

请参阅表生成的完整脚本:
New Table( "20210404_user_web_booking_matrixexample",
Add Rows( 12 ),
Compress File When Saved( 1 ),
New Column( "userID",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values(
[2523, 2523, 2523, 2523, 2523, 2523, 2540, 2540, 2540, 2540, 2540, 2540]
),
Set Display Width( 66 )
),
New Column( "action",
Character( 16 ),
"Nominal",
Set Values(
{"web", "web", "booking", "booking", "web", "booking", "web", "web",
"booking", "booking", "web", "booking"}
),
Set Display Width( 73 )
),
New Column( "date",
Numeric,
"Continuous",
Format( "y/m/d", 12 ),
Input Format( "y/m/d" ),
Set Values(
[3608409600, 3609273600, 3610310400, 3611260800, 3613852800, 3616531200,
3647462400, 3647548800, 3647635200, 3647721600, 3647808000, 3647894400]
),
Set Display Width( 92 )
),
New Column( "first web date to first booking date",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [22, 22, 22, 22, 22, 22, ., ., ., ., ., .] ),
Set Display Width( 150 )
),
New Column( "formula",
Numeric,
"Continuous",
Format( "Best", 12 ),
Formula(
Names Default To Here( 1 );
dat_vec = :date << get values;
web_vec = :action << get values;
user_vec = :userID << get values;
user_index = user_vec == :userID[Row()];
web_index = Matrix(
Substitute( :action << get values, "web", 1, "booking", 0 )
);
web_dat = dat_vec[Loc( user_index & web_index )];
booking_dat = dat_vec[Loc( user_index & !web_index )];
(Minimum( booking_dat ) - Minimum( web_dat )) / (3600 * 24);
),
Set Selected
)
)回复:不同场景同一栏目日差嗨乔安,
经过一番尝试后,我能够生成一组列公式来产生所需的输出(见附件)。 重要的是,该表必须按“userId”和“date”排序才能使公式正常工作。
最好的,
TS
回复:不同场景同一栏目日差嗨乔安,
有几个问题看看是否可以开发一个简单的解决方案:
1) 您是否碰巧有一列可以区分第一个序列(第 1 - 4 行)和第二个序列(第 4 - 6 行);如果没有这个,创建区分两组交易的列公式会更具挑战性。
2) 如果我理解正确的话,第二个预订日期(第 4 行)与您的问题无关。
请在您方便的时候尽早告知我们。
最好的,
TS