Running LET() function as a loop

molylyly

New Member
Joined
Nov 20, 2022
Messages
2
Office Version
  1. 365
Platform
  1. Windows
I have a long LET() function where I define a number of variable but with one of them being a range. Subsequently, I have a number of calculations which depend on the range but I want to make sure that all of the calculations are run fully with the first number in the range before the calculations are done again with the second number in the range. The formula works when calculating with a single number but not with the range. How can I solve this? (I don't have access to LAMBDA, SCAN etc. due to semi annual channel)

Example:
Range {1,3,5}
when range=1, result=20
when range=3, result=50
when range=5, result=26

So I want the result of the formula being {20,50,26}, how do I ensure this?

Formula looks like this where I would like to run a loop for the second part based on the range from "peaks_position"


=LET(
Deficit_period,E26,
Storage_beginning,H26,
Price_period,F26,
Hours,$D$6,
deficit,OFFSET(Deficit_period,,,Hours),
prices,OFFSET(Price_period,,,Hours),
rows,SEQUENCE(Hours),
peaks_position,FILTER(rows,(deficit>0)*(OFFSET(deficit,1,0)<=0)),


rows_peak_position,SEQUENCE(ROWS(peaks_position)),
no_rows_peak_position,SEQUENCE(peaks_position),
rows_offset,rows-1,
table_peaks_position,IF(rows,TRANSPOSE(peaks_position)),
table_pp_na,table_peaks_position-rows_offset,
table_peaks_position_relative,IFERROR(IF(table_pp_na<0,0,table_pp_na),0),
storage_required,IFERROR(SUBTOTAL(9,OFFSET(Deficit_period,rows_offset,,table_peaks_position_relative)),0),
binary_table_pp_relative,IF(table_peaks_position_relative>0,1,0),
deficit_to_peak,IF(rows_peak_position,OFFSET(Deficit_period,,,peaks_position,)),
deficit_to_peak_table,INDEX(IF(binary_table_pp_relative>0,deficit_to_peak,0),no_rows_peak_position),
prices_to_peak,IF(rows_peak_position,OFFSET(Price_period,,,peaks_position,)),
prices_to_peak_table,INDEX(IF(binary_table_pp_relative>0,prices_to_peak,0),no_rows_peak_position),
Deficit_prices_table,IFERROR(INDEX(SORTBY(CHOOSE({1,2},deficit_to_peak_table,prices_to_peak_table),prices_to_peak_table,1,deficit_to_peak_table,-1),no_rows_peak_position,{1,2}),"N/A"),
storage_required_peak,INDEX(storage_required,no_rows_peak_position),
Deficit_sorted_by_p,INDEX(Deficit_prices_table,0,1),
P_min,INDEX(Deficit_prices_table,0,2),
***_deficit,MMULT(IF(SEQUENCE(ROWS(Deficit_sorted_by_p))>=TRANSPOSE(SEQUENCE(ROWS(Deficit_sorted_by_p)))=TRUE,1,0),Deficit_sorted_by_p),
P_min_no,IFERROR(XMATCH(-storage_required_peak,***_deficit,-1),XMATCH(SMALL(***_deficit,1),***_deficit,-1)),
price_marginal,INDEX(P_min,P_min_no),
To_storage,MIN(MAX(IF(price_marginal>=Price_period,storage_required_peak,0))+SUM(IF(prices_to_peak_table<Price_period,deficit_to_peak,0))-Storage_beginning,-Deficit_period),
output,IF(To_storage<0,0,To_storage),

output
)
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Running LET() function as a loop
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Running LET() function as a loop
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
Apologies, cross-posts here and here
 
Upvote 0
Thanks for adding the cross-post links. (y)

Something to consider for the future: Cross-posting is tempting as it seems like a quick/good answer is more likely. However, the opposite may be true as it is common that many of the experienced helpers in any forum don't want to spend time developing a possible solution if one might have already been provided at another forum. It may be that the potential helpers are not members at the other forums and/or may not want to continually check the other forums to see what developments have occurred.
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,199
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top