LAMBDA Examples: Distance between two cities

%3CLINGO-SUB%20id%3D%22lingo-sub-1952946%22%20slang%3D%22en-US%22%3ELAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1952946%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20post%20is%20the%20first%20of%20a%20series%20where%20we%20will%20be%20sharing%20out%20examples%20of%20lambdas.%20This%20is%20intended%20to%20highlight%20lambdas%20we%20have%20cooked%20up%20that%20show%20the%20power%20of%20this%20new%20super-charged%20function.%20Additionally%2C%20you%20have%20the%20opportunity%20to%20engage%20with%20us%20on%20the%20lambdas%20you%20have%20built%20yourself%20and%20of%20course%20let%20us%20know%20how%20our%20own%20formulas%20could%20be%20improved.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20didn%E2%80%99t%20catch%20the%20announcement%2C%20be%20sure%20to%20check%20out%20the%20blog%20post%20highlighting%20the%20release%20of%20this%20new%20function%2C%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fexcel-blog%2Fannouncing-lambda-turn-excel-formulas-into-custom-functions%2Fba-p%2F1925546%22%20target%3D%22_blank%22%3EAnnouncing%20LAMBDA%3A%20Turn%20Excel%20formulas%20into%20custom%20functions%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20today%E2%80%99s%20example%20we%20will%20be%20picking%20up%20where%20we%20left%20off%20in%20the%20announcement%20blog%20and%20making%20good%20on%20the%20promise%20of%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CTABLE%20border%3D%221%22%20width%3D%22100%25%22%3E%0A%3CTBODY%3E%0A%3CTR%3E%0A%3CTD%20width%3D%22100%25%22%20class%3D%22lia-align-center%22%3E%3CEM%3E%E2%80%9Ca%20custom%20function%20that%20takes%20two%20cities%20as%20input%20and%20calculates%20the%20distance%20between%20them...%E2%80%9D%3C%2FEM%3E%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3C%2FTBODY%3E%0A%3C%2FTABLE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESo%20let%E2%80%99s%20get%20to%20it!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1182747180%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747207%22%20id%3D%22toc-hId--1182747210%22%3EDistance%20between%20two%20cities%3C%2FH2%3E%0A%3CP%3EThe%20first%20thing%20to%20note%20is%20that%20this%20function%20will%20be%20making%20use%20of%20%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Fexcel-data-types-stocks-and-geography-61a33056-9935-484f-8ac8-f1a89e210877%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EExcel%20Data%20Types%3C%2FA%3E.%20Data%20Types%20are%20useful%20here%20because%20of%20the%20ease%20at%20which%20we%20can%20retrieve%20latitude%20and%20longitude%20for%20a%20given%20entity%20through%20%E2%80%9Cdot%20notation%E2%80%9D.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22PROPERTYEXTRACT_GIF.gif%22%20style%3D%22width%3A%20532px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F237136i633D4ADD3C59640F%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22PROPERTYEXTRACT_GIF.gif%22%20alt%3D%22Property%20Extraction%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EProperty%20Extraction%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20next%20thing%20to%20cover%20is%20the%20mathematical%20formula%20which%20we%20will%20be%20encoding%20as%20an%20excel%20formula.%20We%20will%20be%20making%20use%20of%20the%20%3CA%20href%3D%22https%3A%2F%2Fwikipedia.org%2Fwiki%2FLaw_of_cosines%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Elaw%20of%20cosines%3C%2FA%3E%20which%20can%20give%20you%20an%20%3CA%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FAs_the_crow_flies%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3Eas%20the%20crow%20flies%3C%2FA%3E%20distance%20calculation.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20formula%20is%20a%20great%20one%20to%20encode%20as%20a%20lambda%20given%20its%20complexity%20which%20will%20make%20it%20more%20prone%20to%20formula-authoring%20errors.%20It%20also%20happens%20to%20re-use%20multiple%20inputs%20which%20makes%20it%20a%20great%20candidate%20for%20%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Flet-function-34842dd8-b92b-4d3f-b325-b8b8f9908999%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ELET%3C%2FA%3E.%20In%20short%2C%20this%20is%20the%20type%20of%20function%20I%20would%20want%20to%20author%20once%20and%20store%20for%20re-use.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20equation%20looks%20like%20this%3A%3C%2FP%3E%0A%3CPRE%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22lawofcosines.png%22%20style%3D%22width%3A%20624px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F237139i32F6E0A05D81A0EC%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22lawofcosines.png%22%20alt%3D%22law%20of%20cosines%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3Elaw%20of%20cosines%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhile%20this%20might%20seem%20a%20bit%20daunting%2C%20the%20inputs%20we%20really%20care%20about%20are%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ELatitude%20and%20longitude%20of%20the%20start%20location%3C%2FLI%3E%0A%3CLI%3ELatitude%20and%20longitude%20of%20the%20end%20location%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EIn%20the%20equation%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%CE%94%CE%BB%20is%20the%20delta%20of%20the%20longitudes%20(%3CEM%3E%3CSTRONG%3E_lon2%3C%2FSTRONG%3E%20%3C%2FEM%3E-%20%3CEM%3E%3CSTRONG%3E_lon1%3C%2FSTRONG%3E%3C%2FEM%3E)%3C%2FLI%3E%0A%3CLI%3E%CF%861%26nbsp%3Band%20%CF%862%20represent%20%3CSTRONG%3E%3CEM%3E_lon1%3C%2FEM%3E%3C%2FSTRONG%3E%20and%20%3CEM%3E%3CSTRONG%3E_lon2%3C%2FSTRONG%3E%3C%2FEM%3E%20respectively%3C%2FLI%3E%0A%3CLI%3E%3CEM%3E%3CSTRONG%3Er%3C%2FSTRONG%3E%3C%2FEM%3E%20is%20equal%20to%20the%20radius%20of%20the%20sphere%2C%20in%20this%20case%206378%20which%20is%20the%20radius%20of%20the%20earth%20in%20kilometers.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EThe%20last%20trick%20we%20employ%20in%20this%20example%20is%20to%20convert%20everything%20into%20radians%20which%20is%20where%20we%20make%20use%20of%20the%20%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Flet-function-34842dd8-b92b-4d3f-b325-b8b8f9908999%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ELET%3C%2FA%3E%20function%20to%20do%20these%20transformations.%20This%20is%20important%20as%20the%20equation%20expects%20lat%2Flong%20in%20radians%20and%20the%20Data%20Types%20return%20them%20in%20degrees.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20is%20illustrated%20in%20the%20first%20series%20of%20name%20definitions%20where%20we%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ECalculate%20the%20values%20in%20terms%20of%20radians%20for%20re-use%3C%2FLI%3E%0A%3CLI%3EAssign%20new%20names%20to%20differentiate%20between%20the%20input%20values%20(%3CSTRONG%3E%3CEM%3E_lat1%2C%20_lon1%2C%20_lat2%2C%20_lon2%3C%2FEM%3E%3C%2FSTRONG%3E)%20and%20transformed%20values%20(%3CEM%3E%3CSTRONG%3Elat_1%2C%20lat_2%2C%20lon_1%2C%20lon_2%3C%2FSTRONG%3E%3C%2FEM%3E)%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EPutting%20all%20those%20concepts%20together%20gives%20us%20the%20following%20solution%20for%20%3CEM%3E%3CSTRONG%3ELATLONGDISTANCE%3C%2FSTRONG%3E%20%3C%2FEM%3Ewhich%20will%20be%20doing%20the%20heavy-lifting%20for%20the%20final%20formula%20that%20takes%20in%20cities%20and%20passes%20in%20their%20respective%20latitudes%20and%20longitudes%20to%20%3CSTRONG%3E%3CEM%3ELATLONGDISTANCE%3C%2FEM%3E%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId--492185706%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185733%22%20id%3D%22toc-hId--492185736%22%3E%3DLATLONGDISTANCE%3C%2FH3%3E%0A%3CPRE%3E%3DLAMBDA(_lat1%2C%20_lon1%2C%20_lat2%2C%20_lon2%2C%20LET(%3CBR%20%2F%3E%20%20%20%20%20lat_1%2C%20RADIANS(_lat1)%2C%3CBR%20%2F%3E%20%20%20%20%20lon_1%2C%20RADIANS(_lon1)%2C%3CBR%20%2F%3E%20%20%20%20%20lat_2%2C%20RADIANS(_lat2)%2C%3CBR%20%2F%3E%20%20%20%20%20lon_2%2C%20RADIANS(_lon2)%2C%3CBR%20%2F%3E%20%20%20%20%20r%2C%206378%2C%3CBR%20%2F%3E%20%20%20%20%20ACOS(%3CBR%20%2F%3E%20%20%20%20%20%20(SIN(lat_1)%20*%20SIN(lat_2))%20%2B%20(COS(lat_1)%20*%20COS(lat_2)%20*%20COS(lon_2-lon_1))%3CBR%20%2F%3E%20%20%20%20%20)%20*%20r%3CBR%20%2F%3E))%3C%2FPRE%3E%0A%3CH3%20id%3D%22toc-hId-1995327127%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327100%22%20id%3D%22toc-hId-1995327097%22%3E%26nbsp%3B%3C%2FH3%3E%0A%3CH3%20id%3D%22toc-hId-187872664%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872637%22%20id%3D%22toc-hId-187872634%22%3E%3DASTHECROWFLIES%3C%2FH3%3E%0A%3CP%3EThe%20last%20piece%20of%20the%20puzzle%20is%20to%20create%20a%20lambda%20which%20will%20take%20two%20cities%20as%20inputs.%20You%20could%20encode%20all%20of%20this%20into%20the%20previous%20formula%2C%20but%20we%20like%20the%20composability%20of%20lambdas%20and%20figured%20it%20would%20be%20a%20great%20way%20to%20show%20lambdas%20calling%20one%20another.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ERevisiting%20the%20previous%20comment%2C%20about%20extracting%20properties%20from%20data%20types%2C%20we%20will%20need%20to%20define%20something%20which%20takes%20two%20cities%20as%20inputs%20and%20then%20extracts%20the%20latitudes%20and%20longitudes.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20this%20we%20will%20make%20use%20of%20dot%20notation%20and%20%3CA%20href%3D%22https%3A%2F%2Fsupport.microsoft.com%2Fen-us%2Foffice%2Flet-function-34842dd8-b92b-4d3f-b325-b8b8f9908999%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ELET%3C%2FA%3E.%3C%2FP%3E%0A%3CPRE%3E%3DLAMBDA(city1%2C%20city2%2C%20LET(%3CBR%20%2F%3E%20%20%20%20%20lat_1%2C%20city1.Latitude%2C%3CBR%20%2F%3E%20%20%20%20%20lon_1%2C%20city1.Longitude%2C%3CBR%20%2F%3E%20%20%20%20%20lat_2%2C%20city2.Latitude%2C%3CBR%20%2F%3E%20%20%20%20%20lon_2%2C%20city2.Longitude%2C%3CBR%20%2F%3E))%3C%2FPRE%3E%0A%3CP%3EWith%20the%20values%20extracted%20and%20names%20defined%2C%20the%20last%20thing%20to%20do%20is%20define%20a%20calculation%20which%20we%20call%20%3CSTRONG%3E%3CEM%3Edistance%3C%2FEM%3E%3C%2FSTRONG%3E%20that%20returns%20the%20value.%20You%E2%80%99ll%20notice%20we%20wrap%20this%20in%20an%20IFERROR%20to%20catch%20any%20errors%20which%20might%20result%20from%20passing%20in%20bad%20values.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3DLAMBDA(city1%2C%20city2%2C%20LET(%3CBR%20%2F%3E%20%20%20%20%20lat_1%2C%20city1.Latitude%2C%3CBR%20%2F%3E%20%20%20%20%20lon_1%2C%20city1.Longitude%2C%3CBR%20%2F%3E%20%20%20%20%20lat_2%2C%20city2.Latitude%2C%3CBR%20%2F%3E%20%20%20%20%20lon_2%2C%20city2.Longitude%2C%3CBR%20%2F%3E%20%20%20%20%20distance%2C%20LATLONGDISTANCE(lat_1%2C%20lon_1%2C%20lat_2%2C%20lon_2)%2C%3CBR%20%2F%3E%20%20%20%20%20IFERROR(distance%2C%20%22an%20error%20occurred%22)%3CBR%20%2F%3E))%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnd%20that's%20it!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22ASTHECROWFLIES_GIF.gif%22%20style%3D%22width%3A%20532px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F237144i549D8A99B7A72CCA%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22ASTHECROWFLIES_GIF.gif%22%20alt%3D%22ASTHECROWFLIES%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EASTHECROWFLIES%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20hope%20you%20found%20this%20example%20useful%20and%20look%20forward%20to%20seeing%20what%20lambdas%20you%20have%20cooked%20up%20on%20your%20own.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUntil%20next%20time!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EChris%20Gross%2C%3C%2FP%3E%0A%3CP%3EProgram%20Manager%20Excel%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1952946%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1953243%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1953243%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20is%20awesome!%26nbsp%3BI'm%20loving%20it!%20LAMBDA%20functions%20will%20be%20a%20game%20changer%20for%20the%20Excel%20heavy%20users!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1956177%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1956177%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F584627%22%20target%3D%22_blank%22%3E%40chgross%3C%2FA%3E%26nbsp%3B%20Measuring%20distances%20amongst%20various%20locations%2Fplaces%20on%20the%20Earth%20with%20the%20help%20of%20MS%20Office%20Excel%20formulas%20is%20really%20fascinating%20and%20awesomely%20great.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1957889%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1957889%22%20slang%3D%22en-US%22%3ELAMBDA%3Athumbs_up%3A%3D)%3Abottle_with_popping_cork%3A%3Apopcorn%3A%3Aparty_popper%3A%3Acollision%3A%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1958773%22%20slang%3D%22de-DE%22%3ESubject%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1958773%22%20slang%3D%22de-DE%22%3EA%20nice%20thing%2C%20the%20world%20has%20become%20a%20little%20bit%20smaller%20for%20everyone%20%3CBR%20%2F%3E%20...%20with%20just%20three%20entries%20in%20Excel%20%3A)).%3CBR%20%2F%3E%3CBR%20%2F%3ENikolino%20%3CBR%20%2F%3E%20I%20know%20that%20I%20don't%20know%20(Socrates)%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1963398%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1963398%22%20slang%3D%22en-US%22%3E%3CP%3EOne%20thing%20with%20%3DLET%20function%20I%20dont%20undestand%3CBR%20%2F%3E%3CBR%20%2F%3EOn%20this%20example%20You%20use%20parameter%20as%20city%20datatype%20and%20col%20param.latitude%3CBR%20%2F%3E%3CBR%20%2F%3Ewhen%20I%20use%20folowing%20example%3CBR%20%2F%3E%3CBR%20%2F%3E%3DLET(t1%2C%20SomeTable%2C%20XLOOKUP(7%2C%20t1%5Bkeycolumn%5D%2C%20t1%5Bvaluecolumn%5D)%20-%20dont%20work%3CBR%20%2F%3E%3CBR%20%2F%3Eso%20.-operator%20works%20with%20variables%20but%20%5B%5D%20indexer%20don't%20work%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3EI%20quess%20sometime%20might%20be%20usefull%20to%20have%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3DLAMBDA(SomeTable%2C%20Key%2C%20XLOOKUP(Key%2C%20SomeTable%5BKeyColumn%5D%2C%20SomeTable%5BValueColumn%5D))%20as%20named%20funktion%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1963700%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1963700%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F64070%22%20target%3D%22_blank%22%3E%40HennSarv%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EReference%20on%20SomeTable%20returns%20an%20array%2C%20actually%20SomeTable%5B%23Data%5D%2C%20not%20the%20table.%20Thus%20t1%20is%20array%2C%20not%20table.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1970189%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1970189%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F584627%22%20target%3D%22_blank%22%3E%40chgross%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECellColor%3C%2FP%3E%3CP%3E%3DLAMBDA(Rng%2C%20GET.CELL(63%2CRng))%3C%2FP%3E%3CP%3ECrashes%20excel%3C%2FP%3E%3CP%3EAny%20way%20to%20get%20this%20to%20work%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%3C%2FP%3E%3CP%3ESam%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1970236%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1970236%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F584627%22%20target%3D%22_blank%22%3E%40chgross%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAre%20there%20plans%20to%20support%20names%20defined%20using%20LAMBDA%20functions%20to%20be%20distributed%20via%20Add-ins%20or%20are%20we%20back%20to%20PERSONAL.xlsb%20Cheers%20Sam%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1970376%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1970376%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F798351%22%20target%3D%22_blank%22%3E%40Sameer_Bhide%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIMHO%2C%20lambda%20management%20shall%20be%20the%20same%20for%20desktop%2C%20online%20and%20mobile%20versions.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1970607%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1970607%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20is%20awesome%20%26amp%3B%20I%20can't%20wait%20to%20get%20my%20hands%20on%20it%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1970609%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1970609%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F798351%22%20target%3D%22_blank%22%3E%40Sameer_Bhide%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGiven%20a%20named%20formula%20%3CEM%3EMyFunc%20%3C%2FEM%3Ein%20Book1%2C%20we%20should%20be%20able%20to%20call%20it%20from%20another%20workbook%20(as%20with%20vba%20functions)%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%3DBook1!MyFunc(123)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20%3CEM%3EMyFunc%3C%2FEM%3E%26nbsp%3B%3DLAMBDA(x%2Cx)%20this%20returns%20an%20error%20on%20my%20build%20but%20I%20assume%20it%20will%20work%20soon.%20Instead%20we%20could%20test%20with%26nbsp%3B%3CEM%3EMyFunc%3C%2FEM%3E%26nbsp%3B%3D%20MyVBAFunc%20where%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EFunction%20MyVBAFunc(x)%3A%20MyVBAFunc%20%3D%20x%3A%20End%20Function%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ETo%20access%20%3CEM%3EMyFunc%3C%2FEM%3E%20as%20an%20add-in%20function%20without%20the%20Book1!%20prefix%20we%20would%20need%20to%20press%20Ctrl%2BF11%20to%20open%20a%20macro%20sheet%20and%20change%20the%20definition%20in%20the%20define%20name%20dialog%20to%20a%20function.%20Or%20equivalently%20from%20vba%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3ENames(%22MyFunc%22).MacroType%3DxlFunction%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFor%20a%20simple%20test%20define%20the%20name%20MyFunc%3A%3D123%20as%20a%20function%20and%20set%20the%20workbook%20IsAddin%20property%20to%20True.%20This%20name%20is%20then%20accessible%20from%20any%20workbook.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1970816%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1970816%22%20slang%3D%22en-US%22%3E%3CP%3EAll%20the%20customs%20formula%20made%20with%20LAMBDA%20to%20be%20a%20way%20to%20stored%2Fexport%20online%20%26amp%3B%20those%20can%20be%20globally%20accessible%20to%20any%20workbook%20under%20that%20M365%20subscription%20account.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIt%20will%20be%20always%20safe%20and%20no%20loss%20of%20function%20in%20case%20of%20system%20crash.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ERegards%2C%20Faraz%20Shaikh%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1973651%22%20slang%3D%22en-US%22%3ERE%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1973651%22%20slang%3D%22en-US%22%3EHello%20will%20you%20be%20able%20to%20assist%20me%20with%20navigating%20excel%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1974971%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1974971%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F288074%22%20target%3D%22_blank%22%3E%40lori_m%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWow%20!%20-%20How%20did%20you%20figure%20that%20out%20-%20I%20am%20going%20to%20give%20this%20a%20shot%20on%20my%20install%20and%20see%20how%20it%20goes.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECheers%3C%2FP%3E%3CP%3ESam%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1975667%22%20slang%3D%22en-US%22%3ERE%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1975667%22%20slang%3D%22en-US%22%3EI%20can't%20use%20my%20Excel%20application.%20When%20I%20ask%20it%20to%20open%2C%20the%20warning%20appears%20that%20it%20cannot%20open%20XLS%20files.%20Or%20the%20changes%20I%20made%20to%20the%20file%20I%20saved%20don't%20appear%20the%20next%20time%20I%20open%20the%20same%20file.%20there%20is%20no%20problem%20with%20word%2C%20but%20I%20definitely%20can't%20work%20with%20XLS%20workshop.%20can%20you%20help%3F%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1975924%22%20slang%3D%22en-US%22%3ERE%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1975924%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F897407%22%20target%3D%22_blank%22%3E%40sadece_Bilal%3C%2FA%3E%26nbsp%3B-are%20You%20tried%20to%20change%20file%20format%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOPen%20file%20-%20ignore%20warning%3C%2FP%3E%3CP%3EPress%20F12%20(save%20as%20command)%3C%2FP%3E%3CP%3ESelect%20new%20file%20type%20-%20Excel%20Workbook%20(xlsx)%20rather%20than%20Excel%202003%20wrokbook%20(xls)%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22HennSarv_0-1607605797304.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F239553i2798459BD76B7ECA%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22HennSarv_0-1607605797304.png%22%20alt%3D%22HennSarv_0-1607605797304.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3Ethen%20close%20and%20reopen%20file%20(the%20last%20step%20is%20for%20safety)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECHeck%20-%20can%20Yu%20now%20work%20with%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1976260%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1976260%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F798351%22%20target%3D%22_blank%22%3E%40Sameer_Bhide%3C%2FA%3E%26nbsp%3BNo.%20XLM%20functions%20cannot%20be%20used%20on%20the%20worksheet.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1976265%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1976265%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F798351%22%20target%3D%22_blank%22%3E%40Sameer_Bhide%3C%2FA%3E%26nbsp%3BYou%20can%20save%20all%20of%20your%20LAMBDA%20formulas%20in%20a%20workbook%20and%20then%20move%2Fcopy%20a%20blank%20worksheet%20from%20that%20workbook%20to%20another%20workbook%20where%20you%20want%20to%20use%20them.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1978108%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1978108%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F15987%22%20target%3D%22_blank%22%3E%40David%20Hager%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECopying%20a%20sheet%20is%20a%20neat%20trick.%20XLM%20functions%20can't%20be%20input%20in%20the%20worksheet%20but%20should%20still%20be%20ok%20within%20names%2C%20this%20is%20still%20in%20beta%20however%20and%20it%20looks%20like%20a%20number%20of%20things%20are%20not%20quite%20how%20they%20should%20be%20yet.%3CBR%20%2F%3E%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F798351%22%20target%3D%22_blank%22%3E%40Sameer_Bhide%3C%2FA%3E%26nbsp%3B%3CBR%20%2F%3EThat%20method%20comes%20from%20having%20spent%20too%20much%20time%20writing%20Excel4%20macros%20even%20before%20VBA%20was%20mainstream!%20XLM%20language%20is%20long%20gone%2C%20as%20you%20say%2C%20but%20the%20same%20environment%20is%20now%20playing%20a%20key%20role%20as%20the%20old%20macro%20functions%20were%20defined%20via%20names%20in%20much%20the%20same%20way%20the%20new%20LAMBDA%20function%20is.%20Another%20little%20known%20feature%20of%20Excel%20is%20that%20every%20session%20has%20a%20hidden%20macro%20workbook%20which%20is%20where%20XLL%20function%20names%20are%20stored.%20In%20fact%20it's%20possible%20to%20copy%20workbook%20names%20to%20this%20hidden%20area%20as%20follows...%3CBR%20%2F%3E%3CBR%20%2F%3EEnter%20the%20formula%20%3CEM%3E%3DMyFunc%3C%2FEM%3E%20in%20A1%2C%20defined%20as%20before%2C%20and%20from%20the%20VBA%20immediate%20window%20execute%20the%20following%20command%20(in%20R1C1%20notation)%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EExecuteExcel4Macro%20%22COPY(!C1%2CTEXTREF(%22%22C1%22%22))%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%3CEM%3EMyFunc%3C%2FEM%3E%20is%20now%20defined%20like%20an%20XLL%20function%20that%20can%20be%20accessed%20from%20any%20open%20workbook%20and%20is%20available%20even%20when%20the%20original%20workbook%20is%20closed.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2007916%22%20slang%3D%22en-US%22%3ERE%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2007916%22%20slang%3D%22en-US%22%3EPmz%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2022960%22%20slang%3D%22en-US%22%3ERE%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2022960%22%20slang%3D%22en-US%22%3EI%20need%20help%20with%20getting%20a%202021%20Calendar%20Excel%20sheet%20so%20I%20can%20Edit%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2022962%22%20slang%3D%22en-US%22%3ERE%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2022962%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F914471%22%20target%3D%22_blank%22%3E%40kfriedelwmcom%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhat's%20the%20link%20between%20Lambda%20and%20Calendar%20template%3F%20You%20may%20File-%26gt%3BNew%20and%20%22calendar%22%20in%20search%2C%20there%20are%20lot%20of%20templates.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2034948%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2034948%22%20slang%3D%22en-US%22%3E%3CP%3EI%20have%20created%20a%20Lambda%20function%20to%20generate%20a%20Fibonacci%20series.%20It%20is%20detailed%20in%20this%20link.%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fexcel%2Flambda-example-generate-fibonacci-series%2Fm-p%2F2034565%22%20target%3D%22_blank%22%3ELambda%20Example%3A%20Generate%20Fibonacci%20series%20-%20Microsoft%20Tech%20Community%3C%2FA%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWould%20love%20to%20know%20if%20there%20is%20any%20way%2C%20we%20could%20improve%20the%20algorithm.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F584627%22%20target%3D%22_blank%22%3E%40chgross%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2035287%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2035287%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F530769%22%20target%3D%22_blank%22%3E%40Viz%3C%2FA%3E%26nbsp%3B%20I%20tried%20Fibonacci%20series%20too%20and%20came%20up%20with%20two%20options%3A%3C%2FP%3E%3CP%3E1.%20Recursive%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EFIB%3A%0A%3DLAMBDA(n%2C%0A%20%20%20%20%20%20IF(n%26lt%3B2%2C%0A%20%20%20%20%20%20SEQUENCE(n%2B1%2C%2C0)%2C%0A%20%20%20%20%20%20LET(b%2CFIB(n-1)%2C%0A%20%20%20%20%20%20%20%20%20%20%20IF(SEQUENCE(n)%3CN%3E%3C%2FN%3E%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E2.%20Non-recursive%20(Binet)%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%3DLAMBDA(n%2CROUND(((1%2B5%5E0.5)%2F2)%5ESEQUENCE(n%2C%2C0)%2F5%5E0.5%2C))%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1971013%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1971013%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F156456%22%20target%3D%22_blank%22%3E%40Faraz%20Shaikh%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAgreed%2C%20ideally%20we%20could%20store%20a%20library%20of%20these%20functions%20accessible%20from%20any%20workbook.%20Function%20scope%20should%20be%20global%20like%20XLL%20%2F%20.js%20custom%20functions%20and%20not%20linked%20to%20a%20particular%20workbook%20as%20with%20VBA%20udfs.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2094069%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2094069%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F584627%22%20target%3D%22_blank%22%3E%40chgross%3C%2FA%3E%26nbsp%3BI%20am%20very%20interested%20in%20the%20interaction%20between%20the%20new%20Data%20Types%20and%20LAMBDAs.%20In%20your%20example%2C%20the%20ASTHECROWFILES()%20function%20works%20with%20the%20City%20Data%20Type%2C%20which%20provides%20the%20Latitude%20and%20Longitude%20fields.%20But%20(I%20presume)%20it%20would%20work%20just%20as%20well%20with%20any%20Data%20Type%20that%20exposed%20these%20two%20numerical%20fields%20with%20the%20same%20names.%3CBR%20%2F%3E%3CBR%20%2F%3EThus%20I%20might%20define%20a%20Data%20Type%20of%20Mountain%2C%20which%20does%20not%20perhaps%20have%20much%20in%20common%20with%20City%2C%20but%20if%20it%20exposed%20the%20%22Coordinates%22%20%3CEM%3Einterface%3C%2FEM%3E%20of%20Latitude%20and%20Longitude%20methods%20could%20still%20be%20used%20with%20AsTheCrowFlies.%20Maybe%20the%20Name%20could%20be%20qualified%20as%20%22Coordinates.AsTheCrowFlies%22%3F%3CBR%20%2F%3E%3CBR%20%2F%3EAs%20I%20come%20from%20a%20C%2B%2B%20background%2C%20this%20is%20starting%20to%20suggest%20generic%2C%20template-based%20programming%2C%20but%20perhaps%20I%20am%20getting%20a%20bit%20carried%20away.%3CBR%20%2F%3E%3CBR%20%2F%3EAs%20an%20aside%2C%20is%20there%20any%20way%20of%20checking%20the%20type%20in%20LAMBDAs%20(or%20other%20formulas)%3F%3C%2FP%3E%3CP%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2094118%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2094118%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F921344%22%20target%3D%22_blank%22%3E%40DS_London%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20see%20no%20difference%20between%20built-in%20Geography%20data%20type%20or%20custom%20one%20like%20Mountain.%3C%2FP%3E%0A%3CP%3EBy%20checking%20the%20type%20you%20mean%20to%20check%20if%20the%20value%20in%20cell%20is%20Data%20Type%20or%20not%3F%20In%20general%20that's%20%3DTYPE(A1)%20returns%20128%20for%20the%20compound%20data.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2094299%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2094299%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3BI%20don't%20quite%20get%20your%20point%3F%20Certainly%20you%20can%20class%20a%20mountain%20as%20Geography%20(though%20the%20built-in%20type%20doesn't%20seem%20to%20recognize%20%22Mount%20Everest%22%20on%20my%20Excel%20at%20least)%2C%20but%20a%20mountain%20is%20certainly%20distinct%20from%20a%20city%20in%20many%20respects.%3CBR%20%2F%3E%3CBR%20%2F%3EFor%20me%2C%20at%20least%2C%20the%20power%20of%20Data%20Types%20is%20the%20ability%20to%20create%20my%20own%2C%20and%20use%20them%20to%20encapsulate%20data%20and%20pass%20them%20around%20(including%20into%20LAMBDA%20functions%20which%20understand%20their%20fields).%20In%20that%20sense%20they%20have%20some%20OOP%20capabilities%20when%20put%20together%20with%20LAMBDA.%3CBR%20%2F%3E%3CBR%20%2F%3EI%20don't%20want%20to%20sidetrack%20this%20LAMBDA%20thread%20into%20a%20Data%20Type%20discussion%2C%20but%20I%20was%20wondering%20how%20you%20could%20tell%20from%20a%20cell%20what%20Data%20Type%20it%20contained%20(beyond%20it%20being%20a%20compound%20type)%3F%26nbsp%3B%3CBR%20%2F%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2094422%22%20slang%3D%22en-US%22%3ERe%3A%20LAMBDA%20Examples%3A%20Distance%20between%20two%20cities%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2094422%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F921344%22%20target%3D%22_blank%22%3E%40DS_London%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20mean%20you%20may%20create%20your%20own%20data%20type%20with%20Power%20Query%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20269px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F249136i9D9CEC096E4BCBA2%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3EAnother%20option%20is%20using%20featured%20table%20in%20Power%20BI%20adding%20it%20to%20Organization%20data%20type.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Microsoft

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. Additionally, you have the opportunity to engage with us on the lambdas you have built yourself and of course let us know how our own formulas could be improved. 

 

If you didn’t catch the announcement, be sure to check out the blog post highlighting the release of this new function, Announcing LAMBDA: Turn Excel formulas into custom functions

 

In today’s example we will be picking up where we left off in the announcement blog and making good on the promise of:

 

“a custom function that takes two cities as input and calculates the distance between them...”

 

So let’s get to it!

 

Distance between two cities

The first thing to note is that this function will be making use of Excel Data Types. Data Types are useful here because of the ease at which we can retrieve latitude and longitude for a given entity through “dot notation”.

 

Property ExtractionProperty Extraction

 

The next thing to cover is the mathematical formula which we will be encoding as an excel formula. We will be making use of the law of cosines which can give you an as the crow flies distance calculation.

 

This formula is a great one to encode as a lambda given its complexity which will make it more prone to formula-authoring errors. It also happens to re-use multiple inputs which makes it a great candidate for LET. In short, this is the type of function I would want to author once and store for re-use.

 

The equation looks like this:

law of cosineslaw of cosines

 

While this might seem a bit daunting, the inputs we really care about are:

  1. Latitude and longitude of the start location
  2. Latitude and longitude of the end location

In the equation

  • Δλ is the delta of the longitudes (_lon2 - _lon1)
  • φ1 and φ2 represent _lon1 and _lon2 respectively
  • r is equal to the radius of the sphere, in this case 6378 which is the radius of the earth in kilometers.

The last trick we employ in this example is to convert everything into radians which is where we make use of the LET function to do these transformations. This is important as the equation expects lat/long in radians and the Data Types return them in degrees.

 

This is illustrated in the first series of name definitions where we:

  1. Calculate the values in terms of radians for re-use
  2. Assign new names to differentiate between the input values (_lat1, _lon1, _lat2, _lon2) and transformed values (lat_1, lat_2, lon_1, lon_2)

Putting all those concepts together gives us the following solution for LATLONGDISTANCE which will be doing the heavy-lifting for the final formula that takes in cities and passes in their respective latitudes and longitudes to LATLONGDISTANCE.

 

=LATLONGDISTANCE

=LAMBDA(_lat1, _lon1, _lat2, _lon2, LET(
lat_1, RADIANS(_lat1),
lon_1, RADIANS(_lon1),
lat_2, RADIANS(_lat2),
lon_2, RADIANS(_lon2),
r, 6378,
ACOS(
(SIN(lat_1) * SIN(lat_2)) + (COS(lat_1) * COS(lat_2) * COS(lon_2-lon_1))
) * r
))

 

=ASTHECROWFLIES

The last piece of the puzzle is to create a lambda which will take two cities as inputs. You could encode all of this into the previous formula, but we like the composability of lambdas and figured it would be a great way to show lambdas calling one another.

 

Revisiting the previous comment, about extracting properties from data types, we will need to define something which takes two cities as inputs and then extracts the latitudes and longitudes.

 

For this we will make use of dot notation and LET.

=LAMBDA(city1, city2, LET(
lat_1, city1.Latitude,
lon_1, city1.Longitude,
lat_2, city2.Latitude,
lon_2, city2.Longitude,
))

With the values extracted and names defined, the last thing to do is define a calculation which we call distance that returns the value. You’ll notice we wrap this in an IFERROR to catch any errors which might result from passing in bad values.

 

=LAMBDA(city1, city2, LET(
lat_1, city1.Latitude,
lon_1, city1.Longitude,
lat_2, city2.Latitude,
lon_2, city2.Longitude,
distance, LATLONGDISTANCE(lat_1, lon_1, lat_2, lon_2),
IFERROR(distance, "an error occurred")
))

 

And that's it!

 

ASTHECROWFLIESASTHECROWFLIES

 

We hope you found this example useful and look forward to seeing what lambdas you have cooked up on your own.

 

Until next time!

 

Chris Gross,

Program Manager Excel

30 Replies

This is awesome! I'm loving it! LAMBDA functions will be a game changer for the Excel heavy users!

@chgross  Measuring distances amongst various locations/places on the Earth with the help of MS Office Excel formulas is really fascinating and awesomely great. 

 

A nice thing, the world has become a little bit smaller for everyone
... with just three entries in Excel :)).

Nikolino
I know that I don't know (Socrates)

One thing with =LET function I dont undestand

On this example You use parameter as city datatype and col param.latitude

when I use folowing example

=LET(t1, SomeTable, XLOOKUP(7, t1[keycolumn], t1[valuecolumn]) - dont work

so .-operator works with variables but [] indexer don't work

I quess sometime might be usefull to have 

=LAMBDA(SomeTable, Key, XLOOKUP(Key, SomeTable[KeyColumn], SomeTable[ValueColumn])) as named funktion 

 

@HennSarv 

Reference on SomeTable returns an array, actually SomeTable[#Data], not the table. Thus t1 is array, not table.

@chgross 

 

CellColor

=LAMBDA(Rng, GET.CELL(63,Rng))

Crashes excel

Any way to get this to work

 

Cheers

Sam

@chgross 

Are there plans to support names defined using LAMBDA functions to be distributed via Add-ins or are we back to PERSONAL.xlsb Cheers Sam

 

@Sameer_Bhide 

IMHO, lambda management shall be the same for desktop, online and mobile versions.

This is awesome & I can't wait to get my hands on it 

@Sameer_Bhide 

Given a named formula MyFunc in Book1, we should be able to call it from another workbook (as with vba functions):

 

=Book1!MyFunc(123)

 

If MyFunc =LAMBDA(x,x) this returns an error on my build but I assume it will work soon. Instead we could test with MyFunc = MyVBAFunc where

 

Function MyVBAFunc(x): MyVBAFunc = x: End Function

 

To access MyFunc as an add-in function without the Book1! prefix we would need to press Ctrl+F11 to open a macro sheet and change the definition in the define name dialog to a function. Or equivalently from vba:

 

Names("MyFunc").MacroType=xlFunction

 

For a simple test define the name MyFunc:=123 as a function and set the workbook IsAddin property to True. This name is then accessible from any workbook.

All the customs formula made with LAMBDA to be a way to stored/export online & those can be globally accessible to any workbook under that M365 subscription account.

 

It will be always safe and no loss of function in case of system crash.

 

Regards, Faraz Shaikh

@Faraz Shaikh 

Agreed, ideally we could store a library of these functions accessible from any workbook. Function scope should be global like XLL / .js custom functions and not linked to a particular workbook as with VBA udfs.

Hello will you be able to assist me with navigating excel?

@lori_m 

Wow ! - How did you figure that out - I am going to give this a shot on my install and see how it goes.

 

Cheers

Sam

I can't use my Excel application. When I ask it to open, the warning appears that it cannot open XLS files. Or the changes I made to the file I saved don't appear the next time I open the same file. there is no problem with word, but I definitely can't work with XLS workshop. can you help?

@sadece_Bilal -are You tried to change file format

 

OPen file - ignore warning

Press F12 (save as command)

Select new file type - Excel Workbook (xlsx) rather than Excel 2003 wrokbook (xls)

HennSarv_0-1607605797304.png

then close and reopen file (the last step is for safety)

 

CHeck - can Yu now work with?

@Sameer_Bhide No. XLM functions cannot be used on the worksheet.

@Sameer_Bhide You can save all of your LAMBDA formulas in a workbook and then move/copy a blank worksheet from that workbook to another workbook where you want to use them.