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

질문됨 일 년 전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
답변함 일 년 전
  • Hi Zac. Thanks for your reply. I tried you solution but there seems to be no prevValue function in AWS Quicksight.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인