Calculate Running difference

0

These are my data fields:

DateMachine IDAccumilated Cycles
01/02/2023 11pmmachine 1200
01/02/2023 12pmmachine 1210
01/02/2023 3pmmachine 2100
01/02/2023 3:30pmmachine 2100

I would like to create a new field called number of cycles by taking the difference between the current and prev row in accumilated cycles. The data needs to be sorted by date and also machine ID.

Thanks in advance

已提問 1 年前檢視次數 211 次
1 個回答
0

So to start I think you will need to define "previous row" since there is not an inherent relation, but rather based on a columns value like date for example. With that said, you can create a calculated field to compute the running difference of Accumulated Cycles for each Machine ID. if you take the Date Field as the ordering, the below may work as solution:

  1. Go to the Analysis page and select Analysis from the top menu.
  2. Select Field Wells.
  3. On the Field wells pane, select the + Add menu at the top and then choose Add calculated field.
  4. In the Create calculated field dialog box, for Name, enter a name for the calculated field, like NumberOfCycles.
  • In the Formula box, paste the following:
{Accumulated Cycles} -
prevValue(
  {Accumulated Cycles},
  1,
  [ASC],
  {Date},
  {Machine ID}
)
  1. Choose Create.

This formula calculates the running difference of Accumulated Cycles for each Machine ID. The prevValue function returns the value of Accumulated Cycles from the previous record as defined by sorting by Date in ascending order within each Machine ID.

Again, this approach assumes that you have data sorted by Date and Machine ID. Also, be aware that this operation can lead to a null value for the first entry of each machine, because there won't be a previous record to subtract from.

Hope this helps!

-Zac

profile picture
Zac Dan
已回答 1 年前
  • Hi Zac. Thanks for your reply. I tried you solution but there seems to be no prevValue function in AWS Quicksight.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南