flex your data

Owen Price – Microsoft MVP

  • LAMBDA
  • SQL
  • Python in Excel
  • Python
  • PowerQuery
  • Excel
  • Video
  • Formulas
  • PowerPivot
  • VBA
  • Formatting
  • Performance
  • Portfolio
  • 5 ideas for new SQL features!

    Blog, SQL

    Last week I wrote about some of the newer innovations in the SQL space. This got me thinking. What other language features would be useful in a SQL environment? This post explores some ideas I’ve had around this. It’s purely speculative, but perhaps it will spark some ideas for you. 1. Optional GROUP BY clause […]

    5 ideas for new SQL features!
  • SQL is changing into something new – are you ready?

    SQL

    On 30 April 2025, DataBricks announced their SQL pipe operator. Without giving you a full rundown of what it is and what it does, here’s a quick example which should give you a good idea. This query: Is now equivalent to this: There’s more to it of course, but that’s the gist of it. It […]

    SQL is changing into something new – are you ready?
  • Exploring NumPy operations with a Python in Excel challenge

    Excel, Python, Python in Excel

    Here’s a data challenge I saw on a LinkedIn post: My goal was to produce the matrix using Python in Excel. The first thing to note is that the matrix is entirely composed of the integers 0 through 9. So: You can see in the image above that the larger matrix is composed of smaller […]

    Exploring NumPy operations with a Python in Excel challenge
  • Use XLOOKUP and XMATCH with regular expressions (regex)

    Blog, Excel, Formulas, LAMBDA

    The Excel team introduced support for regular expressions in May 2024 with three new functions The functions were announced in this post on the Microsoft 365 Insiders blog. As well as these new functions, we learned that we will be able to use regular expressions with XLOOKUP and XMATCH in the near future. Regex coming […]

    Use XLOOKUP and XMATCH with regular expressions (regex)
  • Portfolio – Tableau – Maven Remote Work Challenge

    Portfolio, Tableau

    I created this Tableau Report as an entry for the Maven Analytics Remote Work Challenge in March 2022. Click here to view the Jupyter notebook I used to clean the data, which details my thinking and the steps taken.

  • Better regex results with look-behinds

    Excel

    This post will teach you how to write better regex with look-behinds and look-aheads. All the images in this post are from regex101. An example problem Take these text strings for example: Suppose we want to write a regular expression that extracts all numbers of one or more digits that are enclosed by matched brackets. […]

  • Unfold a list with this new function

    Blog, Excel, LAMBDA

    In this post you’ll learn to unfold a list from a value with a recursion wrapper called LIST.UNFOLD. INTRODUCTION In Excel as in many other languages, we can use REDUCE to reduce (or fold) a list into a single value. We iterate over the list, and at each element apply a function. The result of […]

  • 8-Step Process For Writing Recursive Functions in Excel

    Blog, Excel, LAMBDA

    1. Write a recursive function in Excel2. Realize you could’ve done it with REDUCE3. Write it with REDUCE4. Realize you could’ve done it with dynamic arrays5. Write it with dynamic arrays6. Realize there’s already a built-in function to do it7. Use the built-in function8. 😐

  • Learn A Powerful Technique For Scanning Arrays In Excel

    Excel

    INTRODUCTION In this post, we’ll learn a powerful technique for scanning arrays in Excel. The SCAN and REDUCE functions in Excel allow us to apply a function to each element of an array and, as each function call returns, save the result in an accumulator which is passed as an argument to the function call […]

  • Professional SQL That Will Make Your Queries Shine: INTERSECT vs. INNER JOIN

    Blog, SQL

    When working with databases, it’s crucial to know the best methods to query data effectively. In SQL, two powerful operations that allow you to compare sets of data are the INTERSECT operator and the INNER JOIN clause. Both commands serve the purpose of identifying commonalities between datasets, but they do so in subtly different ways […]

  • Free LAMBDA – SUMPRODUCT for 2D arrays

    Excel

      I wanted to be able to pass a 2D array as a single argument to SUMPRODUCT. But it doesn’t work like that, so I worked around it and created SUMPRODUCT2. This document shows my thought process and steps I went through to get to the final result. I hope you find it interesting. Here’s […]

  • Calculate all pairs from two lists in Excel

    Excel

    Introduction In this post we’ll look at a way to create a LAMBDA function to calculate all pairs from two lists in Excel. F# has a collection of functions for working with lists. Without getting into the details of F# itself, a list is a collection of items. It’s quite similar to a list in Power […]

  • The SWITCH and LET functions – Excel formula performance

    Blog, Excel, Formulas, Performance

    Let me get right to the point. Both SWITCH and unused complex names in LET can slow down your formulas Introduction This formula returns a large array: In the Beta version of Excel I’m using, the above formula can be written like this: I’ll use the shorter version for the remainder of this post. This […]

  • Excel LAMBDA: simplified rolling aggregate of any function

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. Preface This post is a follow up to an earlier post. I wrote the function described there in May of 2022, before I had access to functions like VSTACK and HSTACK and before I had a solid understanding of SCAN and REDUCE. As such, while […]

  • Breadth-first search using Excel

    Blog, Excel, LAMBDA

    The code shown in this post can be found here. What is breadth-first search? Breadth-first search is a popular graph traversal algorithm. It can be used to find the shortest route between two nodes, or vertices, in a graph. For a good primer on how this algorithm works, you can watch this video: Put simply, […]

  • Excel LAMBDA: Create a list of integers

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. The goal Sometimes we may want to create a simple list of integers from some starting value to some ending value. This is easy enough with the SEQUENCE function. For example, suppose we want to create a list of integers from 1 to 10. This […]

  • Excel LAMBDA: parameter checks and function validation

    Excel

    It turns out that if we pass an Excel lambda function as a parameter to another Excel lambda function, we can’t then test that the function passed into that parameter is from a list of allowed functions. Calling the wrapper lambda with any of the other three functions defined below as its sole parameter will […]

  • excel-lambda-ROTATE: rotate an array in Excel

    Blog, Excel, LAMBDA

    The lambda described in this post is in the LAMB namespace, the gist for which can be found here. The goal TRANSPOSE is great. But sometimes it doesn’t do everything I’d like.  So, the goal here is: Create a lambda function that will rotate an array by 90 degrees an arbitrary number of times  A […]

  • Excel LAMBDA: outlier detection functions

    Blog, Excel, LAMBDA

    The gist for this namespace can be found here.  You can download a workbook containing the sample data (sulphates column from Kaggle wine quality dataset), the LAMB namespace, and the OUTLIER namespace here. The goals This is the second of a two-part blog post covering some work I’ve been doing to update and improve some […]

  • Excel LAMBDA: Introducing the LAMB namespace

    Blog, Excel, LAMBDA

    The gist for this namespace can be found here.  The goals When I was first learning about LAMBDA in Excel, I wrote some functions to calculate outlier tests against a column of data.  The main function – OUTLIER.TESTS – allowed us to write a single formula, apply a collection of transformations, and run a standard […]

  • How and why to use namespaces for Excel Lambda functions

    Blog, Excel, LAMBDA

    In programming, a namespace is a grouping for procedures, methods, objects and other code that are related to each other.  We can store Excel Lambda functions in namespaces to keep them organized.  The Advanced Formula Environment To create a namespace, you will need the Advanced Formula Environment (AFE).  If you don’t have AFE, you can […]

  • Video – Learn how to use functions as parameters in Excel

    Blog, Excel, LAMBDA, Video

    An important concept in functional programming is that of functions as parameters. With the introduction of the LAMBDA function, this is now possible in Excel. This short video briefly introduces this concept.

  • Video – Detailed walkthrough of creating a Depreciation Schedule LAMBDA function

    Blog, Excel, LAMBDA, Video

    This post is a follow-up to the original excel-lambda-depn.schedule post. I created the video below to show the steps involved in creating that LAMBDA from scratch, including a modification which allows the schedule to be produced by month as well as by year. some of the text in the video is quite small, so I […]

  • excel-lambda-depn.schedule – Create a depreciation schedule in Excel with one function

    Blog, Excel, LAMBDA

    The gist for the lambdas shown in this post can be found here. When importing this gist, be sure to select “Add formulas to new namespace” and use the name “depn”. The goal There are several methods of calculating depreciation in Excel. The functions SLN (straight line) , DB (declining balance) , DDB (double declining […]

  • Lambda presentation to Microsoft Excel and Data Analysis Learning Community on July 31st, 2022

    Blog, Excel, LAMBDA, Video

    On July 31st, 2022, I gave a presentation about Excel Lambda functions to the MS Excel Toronto Meetup group. If you have any questions about the content of the video or the file, please leave a comment.

  • excel-lambda-KNN – classify data using K-nearest neighbors (KNN) in Excel

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. The goal The goal in this post is: Create a function to classify data using K-nearest neighbors (KNN) in Excel A solution Here’s a lambda function called KNN: I’ve also included the definition of the FREQ.SIMPLE lambda function. That function produces a two-column frequency table […]

  • excel-lambda-FREQ.SIMPLE – create a simple frequency table in Excel with one function

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. The goal The goal in this post is: Create a simple frequency table in Excel with one function A solution Here’s a lambda function called FREQ.SIMPLE: FREQ.SIMPLE has one parameter and as such accepts one argument. data – a single-column array of data. This is […]

  • Lambda presentation to MS Excel Toronto Meetup Group on July 13, 2022

    Blog, Excel, LAMBDA, Video

    On July 13th 2022, I gave a presentation about Excel Lambda functions to the MS Excel Toronto Meetup group. You can download the file used in the presentation here. If you have any questions about the content of the video or the file, please leave a comment.

  • excel-lambda-CONVERTRECIPE – Convert recipe ingredients to different units in Excel

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. The goal Here’s a picture of a red velvet cake I baked last week.  I baked this cake from scratch for my son’s birthday. I’m not a baker. But it makes a nice change from working with computers.  Because I’m English, I get most of […]

  • excel-lambda-GETHOLIDAYS – Calculate holiday dates for any year in Excel

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. You can download a workbook with example definitions of relative and fixed holidays here. The goal When working with dates in Excel, it’s sometimes useful to have an accurate list of the public holidays in a given year so we can calculate (for example) the […]

  • excel-lambda-INTRATE.EFFECTIVE – calculate effective interest rate in Excel without iterative calculation

    Blog, Excel, LAMBDA

    The gist for this lambda can be found here. The goal I saw a video from Diarmuid Early in which he discusses the use of the iterative calculation setting in Excel for calculating effective interest rates.  I share a similar view that using that setting can be very dangerous and if possible, it’s best to […]

  • excel-lambda-PMT.DATES – create a list of dates for a payment schedule in Excel

    Blog, Excel, LAMBDA

     The gist for this lambda function can be found here. The goal Inspired by Diarmuid Early‘s YT video “Debt 101” and Brent Allen‘s “Generating an Amortization Schedule” post on his blog, the goal here is Simplify the creation of a series of dates to be used as payment dates for a debt instrument This series […]

  • What’s the difference between ROLLUP and GROUPING SETS in SQL?

    Blog, SQL

    The full script for this post can be found here. This post uses the AdventureWorksDW database in SQL Server 2019 Express.  Depending on your preference, you can either watch this video or read below. The goal Suppose we have a request to produce a report: Create a report showing internet sales amount with these columns: […]

  • Excel – Introduction to Analyze Data (video)

    Blog, Excel

    Watch the video below and learn about Analyze Data in Excel.  The limitations of Analyze Data and why it sometimes won’t work Use Natural language to  Automatically discover insights in your data Automatically create useful pivot tables and pivot charts Automatically recognize mis-spelled column names Automatically filter your data without writing complex functions

  • excel-lambda-CORRELMATRIX – Calculate a correlation coefficient matrix in Excel

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. The goal When we have a dataset with lots of variables (features), we can simplify the modeling process by first trying to determine which variables are correlated with one another.  If two variables are highly correlated, we can consider including only one of them in […]

  • SQL: Numerical row constructor comparisons in PostgreSQL and MySQL

    Blog, SQL

    The full script for this post can be downloaded here. The following post was written primarily in Postgres 14 and tested in both Postgres and MySQL. While the data generation and use of EXCEPT are not supported natively in MySQL, the principles of row comparisons are equivalent. Setup To demonstrate how a row constructor comparison […]

  • SQL: Use LAG and SUM window functions to group rows

    Blog, SQL

    What is Advanced SQL, anyway? I think about this sometimes. Is it window functions? CTEs? I don’t know. Some of it is trickier than others. I think it’s relative to how much practice you’ve had and depends a great deal on the data in front of you. Anyway, I saw this post on LinkedIn by […]

  • excel-lambda-RANK.DENSE – An Excel lambda function for DENSE_RANK from SQL

    Blog, Excel, LAMBDA

    The gist for this lambda can be found here. The goal There are many reasons for ranking data. Excel provides a few native functions to do so. The two main ones are RANK.AVG and RANK.EQ. Each function will return the integer rank of a number within a list of numbers, sorted either descending or ascending […]

  • excel-lambda-pd.rolling.aggregates – calculate rolling sum in Excel (and much more)

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. You can download an example file here. The goal If we have a table of sales of a product where each row represents one month, then we might want to calculate – for each month – the rolling sum of sales over the most recent […]

  • What is a thunk in an Excel lambda function?

    Blog, Excel, LAMBDA

    This is my attempt to answer a question I have asked myself many times over the last few months: What is a thunk in an Excel lambda function? Background Many of the new dynamic  array functions that create arrays, such as MAKEARRAY, SCAN, REDUCE and so on, will not allow an element of the array […]

  • excel-lambda-pd.qcut – Group a continuous variable into bins of equal counts

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. The goal It’s sometimes useful to be able to group a continuous variable into bins of equal counts such that we can work with that variable as it if were discrete. In mathematics and machine learning applications, this process is sometimes referred to as “discretization”. […]

  • excel-lambda-CLEANCURRENCYTEXT – Convert currency stored as B or M to a number with just one function

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. The goal Sometimes we might have numbers in an Excel file formatted like this: I’d like to create a function that those values into a number where each value is at the same scale. A solution I say “a” solution, because I’m sure there are […]

  • powerquery-m-clean-currency-text – Convert currency stored as B or M to a number in PowerQuery

    Blog, PowerQuery

    The gist for this pattern can be found here. The goal Sometimes we might have numbers in a text file formatted like this: I’d like to create a custom column that converts this text into a currency data type, preserving the scale of the suffix in each row and preserving the currency symbol. A solution […]

  • excel-lambda-OUTLIER.TEST – transform, test and flag a variable for outliers in Excel with one function

    Blog, Excel, LAMBDA

    The gist for this set of functions can be found here. The goal This post is not intended to be an instruction on the mathematics or theory of outlier detection. My intention is to demonstrate another way we can use lambda in Excel to simplify a common task. This post will show you how to […]

  • excel-lambda-FORECAST.ETS.COMPARE – Build a forecast for comparison with actuals with a single formula

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. Forecasting in Excel Excel comes with several functions that allow us to quickly produce forecasts on time-series datasets. Data>Forecast Sheet One method you can use is the “Forecast sheet” button which can be found on the “Data” tab of the ribbon in Excel versions 2016 […]

  • excel-lambda-GROWTHFROMOFFSET – Calculate % growth of current month over 12 months before

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. I was straining my brain to understand the lambdas posted by user XLambda on the lambda forum at mrexcel.com. This person is really mining the depths of what’s possible with lambda in Excel. I go there frequently when I want to understand how to do […]

  • excel-lambda-DESCRIBE: UPDATED AND IMPROVED – Get descriptive statistics in Excel with just one formula

    Blog, Excel, LAMBDA

    Quick start If you want to use this function to get descriptive statistics in Excel with just one formula and without reading all the detail below, you will need to: create a LAMBDA function called RECURSIVEFILTER using this gist create a LAMBDA function called GROUPAGGREGATE using this gist create a LAMBDA function called DESCRIBE using […]

  • excel-lambda-LEV: Calculate the Levenshtein Distance in Excel

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. A friend of mine challenged me to implement a LAMBDA to calculate the Levenshtein Distance in Excel. As a reminder, the Levenshtein Distance represents the fewest number of insertions, replacements or deletions that are necessary to change one text string into another. For example, given […]

  • excel-lambda-GROUPAGGREGATE: Quickly create summary tables in Excel with just one formula

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. Let me cut to the chase. I have some data from Wikipedia for population by country . I’ve also got some data of land area by country, from here. I created a Power Query to merge them. The output looks like this: There are 195 […]

  • excel-lambda-RECURSIVEFILTER: Use Excel’s FILTER function with dynamic lists of filters

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. Excel’s FILTER function lets you take an array of data (or a table, or a range) and filter it with an “include” array of TRUE/FALSE values, where each row in the include array corresponds to each row in the data array. If the include array […]

  • excel-lambda-DESCRIBE (simple): Get descriptive statistics in Excel with this LAMBDA function

    Blog, Excel, LAMBDA

    The lambda described in this post has been updated with additional features. You can read that post here. You can use the Data Analysis Toolpak to get descriptive statistics in Excel for a variable in your data. First, you need to make sure the analysis toolpak is activated as an Add-in: Then you select “Data […]

  • excel-lambda-ONEHOT: One-hot encode categorical data with LAMBDA

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. One-hot encoding. Create as many columns as there are unique values in a variable. Put a 1 in a cell if the column and row represent the same value, otherwise put a zero in the cell. Use these new columns to create ML models. Do […]

  • excel-lambda-NGRAMS: Get n-grams from a text string using this LAMBDA function

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. A common task in Natural Language Processing (NLP) is to tokenize text strings into n-grams. This can be done easily in languages like Python, Scala, R and others. They have very good libraries for performing that kind of task at scale. I wanted to see […]

  • Excel: Un-Merge Cells And Fill Each Cell With Original Value Using VBA

    Blog, Excel, Formatting, VBA

    Do you sometimes receive a file with merged cells all over the place? Something like this: The first thing I want to do in that situation is un-merge everything. Well, that’s easy enough. If I use the Merged Cells button on the ribbon, it will do this: Ok, now I need to fill in the […]

  • excel-lambda-ARRAYUNION: Join Two Ranges Or Arrays Of Data Together Using This LAMBDA Function

    Blog, Excel, LAMBDA

    You may have found yourself wanting to join two arrays together in Excel. This function will quickly append and optionally deduplicate two single-column arrays or ranges of data. This is done with the LAMBDA shown above, which you can define in Excel’s Name Manager with the name ARRAYUNION. It accepts 3 arguments: array_a – a […]

  • excel-lambda-SQLVALUES: Format A Row Of Data For SQL INSERT

    Blog, Excel, LAMBDA

    The gist for this lambda function can be found here. If you sometimes need to quickly put some Excel data into a SQL table or use the data in a CTE, you may have found yourself doing something like this: Here’s a LAMBDA I’ve called SQLVALUES: =LAMBDA(t,LET(d,IFS(ISTEXT(t),”‘”&SUBSTITUTE(t,”‘”,”””)&”‘”,ISBLANK(t),”NULL”,LEFT(MAP(t,LAMBDA(x,CELL(“format”,x))),1)=”D”,TEXT(t,”‘YYYY-MM-DD HH:mm:ss’”),TRUE,t),”(“&TEXTJOIN(“,”,FALSE,d)&”)”)) This will: Wrap the tuple in parentheses […]

  • excel-lambda-CHARACTERS: Split An Alphanumeric String Into An Array Of Characters

    Blog, Excel, LAMBDA

    =LAMBDA(rng,vertical,LET(chars,MID(rng,SEQUENCE(LEN(rng)),1),IF(vertical,chars,TRANSPOSE(chars)))) This LAMBDA function takes two arguments: rng – a cell containing a text string vertical – TRUE/FALSE. If TRUE, the LAMBDA will return a vertical array of the characters in rng. If FALSE, the LAMBDA will return a horizontal array of the characters in rng In my file, I have named this LAMBDA “CHARACTERS”. […]

  • excel-lambda-NONEMPTYROWS: Filter Out Rows With Empty Cells

    Blog, Excel, LAMBDA

    If you want to quickly get all rows which don’t have any blanks in any columns, you can combine FILTER, BYROW and AND, like this: =FILTER(range,BYROW(range,LAMBDA(r,AND(r<>””)))) Here, I’ve defined a LAMBDA function, which is really just a way of applying some logic (in the second parameter) to some data (in the first parameter). I have […]

  • Excel: Calculate The Difference Between “Percentage Of Column Total” Columns

    Blog, Excel, PowerPivot

    I downloaded some data from the USDA FAS custom query builder. The file contains the area harvested of corn in many harvest years for non-US countries. I want to calculate the % of non-US corn area that each country represents in the latest two full harvest years and then calculate the change in percentage points […]

  • Excel: Use Names To Make Your Formulas Easier To Read

    Blog, Excel

    There’s a useful but under-used feature in Excel that can make your formulas much easier to read and understand. In the image below, the Name Box is the white box where it says A2. You can see that I have an Important Value in cell A2. I’m going to use that value all over my […]

flex your data

Owen Price – Microsoft MVP