cancel
Showing results for
Did you mean: Anonymous
Not applicable

## Calculations in Flow

Hi All,

I am using flow to insert data into CDS at day and monthly levels. My flow is like this- So when a record is created in "A" entity then check it is monthly of daily input and in list records, I am using dim_date table and inserting data in "B" entity accordingly. I want to do one calculation in flow. I have created a flow that inserts data at day and month level and now I want to do some calculation. Suppose I have one column named X  as shown in the below image. I want to create column Y  which has values - summation of values diagonally from column X.

So column Y will be like

1)650000

2)650000+650000 =1300000
3)1300000+650000=1950000

and so on How can I do it in flow?

1 ACCEPTED SOLUTION

Accepted Solutions  Solution Sage

Hi @Anonymous ,

You can do it by using Initializing two variables of type int with value being 0 with one being temp variable and other being Y . Then inside Apply to each loop use Set Variable action to set Temp variable to variable Y. Then in next step use another Set Variable action to set Y using add (X, Temp) and in update action use Variable Y.

Please note if you are using concurrency this will not work .

Thanks

2 REPLIES 2  Solution Sage

Hi @Anonymous ,

You can do it by using Initializing two variables of type int with value being 0 with one being temp variable and other being Y . Then inside Apply to each loop use Set Variable action to set Temp variable to variable Y. Then in next step use another Set Variable action to set Y using add (X, Temp) and in update action use Variable Y.

Please note if you are using concurrency this will not work .

Thanks Anonymous
Not applicable

Hi @ManishJain ,

It worked. One more doubt

Suppose, I have data like this-
Record     Val     X       Y
1               45    1         1
2               67
Here I can update only X and Y is calculated based on X.
The first time when record 1 is updated then it shows respective X and Y.
The second time when I update record 2 then it should hold the previous value of Y. If I insert X=2 then Y =3(inserted X value + previous Y value)and the output should look like this. Earlier I was creating data monthly so your logic didn't create any problem. But now I am updating those records to update different fields but need the same kinda calculation.   