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

asked 10 months ago206 views
1 Answer
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
answered 10 months ago
  • Hi Zac. Thanks for your reply. I tried you solution but there seems to be no prevValue function in AWS Quicksight.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions