Forum Discussion
Chris_Gross
Microsoft
Dec 03, 2020LAMBDA Examples: Distance between two cities
This post is the first of a series where we will be sharing out examples of lambdas. This is intended to highlight lambdas we have cooked up that show the power of this new super-charged function. Ad...
DS_London
Jan 25, 2021Copper Contributor
Chris_Gross I am very interested in the interaction between the new Data Types and LAMBDAs. In your example, the ASTHECROWFLIES() function works with the City Data Type, which provides the Latitude and Longitude fields. But (I presume) it would work just as well with any Data Type that exposed these two numerical fields with the same names.
Thus I might define a Data Type of Mountain, which does not perhaps have much in common with City, but if it exposed the "Coordinates" interface of Latitude and Longitude methods could still be used with AsTheCrowFlies. Maybe the Name could be qualified as "Coordinates.AsTheCrowFlies"?
As I come from a C++ background, this is starting to suggest generic, template-based programming, but perhaps I am getting a bit carried away.
As an aside, is there any way of checking the type in LAMBDAs (or other formulas)?
SergeiBaklan
Jan 25, 2021MVP
I see no difference between built-in Geography data type or custom one like Mountain.
By checking the type you mean to check if the value in cell is Data Type or not? In general that's =TYPE(A1) returns 128 for the compound data.
- DS_LondonJan 25, 2021Copper Contributor
SergeiBaklan I don't quite get your point? Certainly you can class a mountain as Geography (though the built-in type doesn't seem to recognize "Mount Everest" on my Excel at least), but a mountain is certainly distinct from a city in many respects.
For me, at least, the power of Data Types is the ability to create my own, and use them to encapsulate data and pass them around (including into LAMBDA functions which understand their fields). In that sense they have some OOP capabilities when put together with LAMBDA.
I don't want to sidetrack this LAMBDA thread into a Data Type discussion, but I was wondering how you could tell from a cell what Data Type it contained (beyond it being a compound type)?- SergeiBaklanJan 25, 2021MVP
I mean you may create your own data type with Power Query
Another option is using featured table in Power BI adding it to Organization data type.
- DS_LondonJan 25, 2021Copper Contributor
SergeiBaklan Yes, this is what I have been doing. It was just that my sheet is a little more involved and I was trying to bring out a more general comment, using the original example. I wanted to show my appreciation of how LAMBDA and Data Types fit so well together. The creation of Data Types paired with specific LAMBDAs to make use of them is very interesting.