不同場景同列日差您好,我對以下不同場景有疑問。 非常感謝任何幫助!
場景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