I am running into a problem with a formula. So far i got it to work summing a YTD value based on a index & match function but i get one issue.

It retrieves the rante total that are in page "Budget" but are is fixed. So if lines are not in that order or we add lines the values retrived are incorrect.

How can i index the account name in collumn C sheet "c) P&L Comparisions" to sum if name is equal + current formula summing YTD range based on input of month in cell D1

Attached the example that has the working formula... i guess its easier to explain

File Example

Any help is much appreciated. I guess i spent over 4 days banging my head on this issue through multiple aproaches and documentation and nothing so far.