Hi there. I have a tableau calculation I'd like to...
# gooddata-platform
j
Hi there. I have a tableau calculation I'd like to replicate in MAQL. In tableau the metric would be like: Metric_1 = PREVIOUS_VALUE (Metric_1) + ZN(LOOKUP(Metric_2),-1)) So I’d like the metric to add the previous value of a Metric_1 for the row, within the table, then look at and add the value for Metric_2 from the previous row. Hence the metric would be looking at values within its own table that it’s been placed in and use the values from previous rows in the table, containing the metric itself and create the value of the next row. My description is perhaps not the easiest, so here is a video of what I’d like to achieve and how its done in tableau, from 14:30 -15:30 in the

Youtube

tutorial for how to create the table. Thanks! :)
j
Hi Josefin, by "previous" you mean previous by time or even by non-time attribute? AFAIK there are the following potentially relevant MAQL features: • Time transformationsRanking functions Could it help in your case? Note: the links go to DOC related to GoodData.CN platform, but should be valid for the hosted platform as well.
j
Hi Jan! By previous, I mean a value of the previous row within the table. So if I was to add the metrics (M1 and M2) to a table, it would work like this in the table:
Copy code
M2	      M1
Row1	M2_row1	  M1_row1 = (M1_row1 + M2_row1)
Row2	M2_row2	  M1_row2 = (M1_row1 + M2_row1)
Row3	M2_row3	  M1_row3 = (M1_row2 + M2_row2)
Hope this clarifies a bit on what I'm trying to achieve, and if not - the video I sent in the first message explains it a lot better 🙂
j
Understand. Still you did not answer my question if you search for previous value by date or by non-date 😉
j
Indeed, that'd be a non-date in this case.
j
OK. AFAIK for non-date attributes we do not have anything like FOR PREVIOUS time transformations. @Jakub Sterba please, comment on this.
j
@Jan Soubusta is right. FOR PREVIOUS and running total functions like RUNSUM work currently only with date attributes.
p
🎉 New note created.
j
For tables sliced by date attribute (e.g. row per day or row per month) you can use running total functions (e.g. RUNSUM) with defined window (e.g. BETWEEN 1 ROW PRECEDING AND 1 ROW PRECEDING) to refer to previous row or FOR PREVIOUS function to refer to data for previous ordinal value (e.g. previous day, previous month). These two options make a difference if there are some periods without data in the series.
j
Alright, thanks for the replies 🙂