0

I have this Google Sheet file using this formula to split and flatten the input in B2:B3

=ArrayFormula(LAMBDA(sp, FLATTEN(SPLIT(sp, "♥"))))(BYROW(A2:A3, LAMBDA(rp, REPT(B2:B3&"♥",rp))))

I encounterd this error

Error
Invalid call to non-function.

enter image description here

What is it and How to solve it?

2
  • Remove array formula. Commented Sep 28, 2022 at 16:18
  • @Harun24hr That solves it, but give some in general explanation in an answer. Commented Sep 28, 2022 at 16:31

3 Answers 3

3

The error that you have received will mean that the formula was not able to call the parameter that your function was expecting, checking both of the 2 formulas that you have made:

LAMBDA(sp, FLATTEN(SPLIT(sp, "♥")))
And
LAMBDA(rp, REPT(B2:B3&"♥",rp))

Both of them are calling a range being this part of the formula expression however there is no really a valid value to be passed to the expression so it can "call it" to provide the result.

In a nutshell, the error "Invalid call to a non function" means that in your formula you have put the call parentheses "()" which contains the data that will be called to the function that you have named but this data can't be called.

An example of this error can be made with the following LAMBDA formula:

=LAMBDA(test, test())(A1) 

Using this formula will display the same exact error and this is due to the parameter being "called" it's invalid, this is due to the data being called a range and not a valid function.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi thanks Gabriel for the response, could you Include a comparison between this =LAMBDA(test, test())(A1) , and what it should be with your simple example.
Sure, an example would be: =LAMBDA(test,test())(LAMBDA(5)), this function will pretty much return 5 but this is because it's returning a valid call since test was expected to be a function and it was passed a LAMBDA(5) which basically returns a function
0

You can try this formula for lambda approach.

=LAMBDA(Rpt,Rpn,QUERY(INDEX(FLATTEN(SPLIT(REPT(Rpt&"♥",Rpn),"♥"))),"where Col1 is not null"))(B2:B3,A2:A3)

Without lambda-

=QUERY(INDEX(FLATTEN(SPLIT(REPT(B2:B3&"♥",A2:A3),"♥"))),"where Col1 is not null")

enter image description here

2 Comments

The porpuse is not the formula it selfe instead is What is this error and How to solve it in general? can you give some info why is that?
@Osm I will make an explanation on that error.
0

I think the issue is that you are calling a vertical range B2:B3 from within the internal LAMBDA that is not defined as part of the range to be passed to it from the BYROW that is calling it. I think a MAP would be more appropriate than the BYROW in this case as you can then feed multiple ranges into the LAMBDA it calls:

=arrayformula(lambda(flt,filter(flt,flt<>""))(lambda(sp,flatten(split(sp,"|")))(map(A2:A3,B2:B3,lambda(a,b,rept(b&"|",a))))))

N.B. - The additional outer lambda is required to filter out the empty cells that will occur when sp is flattened if the numbers of repeats in B2:B3 is not the same (as jagged arrays aren't allowed). This could obviously also be done with a QUERY, but here is one way of doing it with LAMBDAs all the way through.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.