cancel
Showing results for
Did you mean:
Regular Visitor

## For loop over rows comprising multiple columns

Hi,

I am trying to interate over rows and calculate this equation for my new column:

For every row:

if column1[i] = 1 then Newcolumn[i] =0

Else Newcolumn[i] = MAX(0, MAX(Newcolumn[i-1]+column2[i])+column3[i])

 column 1 column2 column3 new column new column formula 0 0 1 -1000 -100 0 0 0 -1000 1500 1500 max(0,max(0,0-1000)+1500)=1500 0 0 100 1600 max(0,max(0,1500+0)+100)=1600 0 -1000 -60 540 max(0,max(0,1600-1000)-60)=540 1 -1000 1000 1000 0 all values are <=0

I tried to implement it with List.Accumulate, however, I have a problem calling three different columns in their expression. My main problem is the 2nd max function comprising the recursive term.

I also implement it as a recursive function but it never stops.

I hope one could help me! It's been more than a week and I am still struggling with it.

Thanks a lot

Elnaz

2 REPLIES 2
Super User III

You are going to need to post some data so someone here can help.

How To Ask A Technical Question If you Really Want An Answer

How to Get Your Question Answered Quickly - Give us a good and concise explanation
How to provide sample data in the Power BI Forum - Provide data in a table format per the link, or share an Excel/CSV file via OneDrive, Dropbox, etc.. Provide expected output using a screenshot of Excel or other image. Do not provide a screenshot of the source data. I cannot paste an image into Power BI tables.

Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling

Proud to be a Super User!

MCSA: BI Reporting
Regular Visitor

Thanks for the tip. The example is as follow:

For every row:

if column1[i] = 1 then Newcolumn[i] =0

Else Newcolumn[i] = MAX(0, MAX(Newcolumn[i-1]+column2[i])+column3[i])

 column 1 column2 column3 new column new column formula 0 0 1 -1000 -100 0 0 0 -1000 1500 1500 max(0,max(0,0-1000)+1500)=1500 0 0 100 1600 max(0,max(0,1500+0)+100)=1600 0 -1000 -60 540 max(0,max(0,1600-1000)-60)=540 1 -1000 1000 1000 0 all values are <=0

Announcements