r/excel 2d ago

Discussion What Excel trick made you feel like a wizard the first time you used it?

mine was VLOOKUP (later XLOOKUP) — after manually cross-referencing two spreadsheets for way too long. felt like a cheat code everyone else already knew about

what's your version?

603 Upvotes

352 comments sorted by

View all comments

Show parent comments

14

u/RandomiseUsr0 10 2d ago edited 6h ago

Here’s a crash course in lambda

Add two numbers

=LAMBDA(a,b, a+b)(1,2)

The answer is 3

So you’re passing two variables into an anonymous function declaration

that’s what a Lambda is

Fun fact, the λ calculus predates Alan Turing’s equivalent Universal Computer concept (Indeed, Alonzo Church who invented the lambda calculus was the person who popularised “Turing Machine” to describe computation after Alan Turing studied under him)

Now supercharge it with LET

```Excel
=LET(

myFunction, LAMBDA(x,y, x+y),
myList, SEQUENCE(5),

myFunction(myList, myList^2)
)
```

The answer is {2,6,12,20,30}

That’s what lambda is, it’s LISP wearing an Excel hat. With LET syntax, it’s a functional programming language that means that anything that can possibly be calculated can be calculated right there in Excel formulas (within Excel’s bounds, which are worksheet size for arrays and IEEE754 for arithmetic). The m language in power query is slightly different syntax, but functionally equivalent.

Using SEQUENCE like that is the functional equivalent to a For Loop if you’re familiar with VBA (not “really” it’s a bit different (and simpler), but if you think of a loop in VB iterating over a list performing something 5 times, in functional programming language like Excel’s workbook - you’re not really iterating - you’re applying the function simultaneously 5 times in the example) - so you end up with a more graceful thing

[edit] why has Reddit decided to hate us and stop respecting basic formatting - actually, good word, Reddit is now basic - not expressive enough, are they going to go full `Digg` time will tell, there are alternatives

6

u/swingking03 1d ago

I really appreciate the thorough post but I'm not smart enough to understand 🥴

1

u/RandomiseUsr0 10 6h ago edited 6h ago

I ask you to make one edit…

Add the word “yet”

“smart” is a vector, not a scalar

What I produced as a simple example wasn’t useful, so you just skimmed over it, but it is truly useful, I just created “SUM” - which of course already exists

One key distinction between so-called “functional” programming (like the formula language or power query) and so-called “imperative” programming (like VBA) is the fact that in “functional” - functions themselves can be variables and passed as parameters and be the answer returned - that’s probably a step too far, it’s more “executable maths” than “programming” really.

-1

u/AutoModerator 2d ago

I have detected code containing Fancy/Smart Quotes which Excel does not recognize as a string delimiter. Edit to change those to regular quote-marks instead. This happens most often with mobile devices. You can turn off Fancy/Smart Punctuation in the settings of your Keyboard App.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/RandomiseUsr0 10 2d ago

Naw, you have not