cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Elnaz91
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 1column2column3new columnnew column formula
   00
1-1000-10000
0-100015001500max(0,max(0,0-1000)+1500)=1500
001001600max(0,max(0,1500+0)+100)=1600
0-1000-60540max(0,max(0,1600-1000)-60)=540
1-1000100010000
 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
edhans
Super User III
Super User III

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

 

How to get good help fast. Help us help you.

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 I answer your question? Mark my post as a solution!
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
Elnaz91
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 1column2column3new columnnew column formula
   00
1-1000-10000
0-100015001500max(0,max(0,0-1000)+1500)=1500
001001600max(0,max(0,1500+0)+100)=1600
0-1000-60540max(0,max(0,1600-1000)-60)=540
1-1000100010000
 all values are <=0   

 

 

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors