Introduction
from our sales transaction table we want a single-cell formula that when I enter it it delivers the report in a single cell with a unique list of date and product and the sum of sales now back in Excel magic trick 1671 we saw how to do this type of report and we had one two three different formulas but in the comments below Excel wizard posted the formula we're gonna see now the formula we're going to create here only works in Microsoft 365 if you're in earlier versions what we're gonna do was not possible and of course in those old days we used pivot tables but the beauty of a single cell formula of course is it instantly updates when anything changes.
Three Formula Solution
now the first function we're going to use is the unique function I want to highlight from this excel table the date column and the product column close parentheses because there's two columns this will give me a unique combination of all the dates and products now when I hit enter we can see the formula doesn't live in any of the other cells just the top cell also we want a format this column as a date.
Formula only works in Microsoft 365 Excel
now we want to sort this so in the very top cell f2 we use another spilled array function sort and we're gonna use comma the second arguments or index I want to sort by the first then the second column I put that inside of array syntax close parentheses and now when I enter the column is sorted first by date and then within date product.
UNIQUE Function
now we're gonna have to use that result a few times in our formula so one of the amazing functions that just does not exist in any other version except for Microsoft 365 is the LAT function it allows us to define a variable we're gonna call it u that's the name comma there's the variable and then comma at the end that's where our single-cell formula is going to go.
SORT Function with array in second argument to sort first, then second column.
now what we need to do is I need to pull the date and the product and then add a sales column and the way we're going to do that is we're going to use the choose function choose is a great function that allows us to have an index number and for us we're gonna need three columns so 1 comma 2 comma 3 and choose can take single columns and join them together from 3 individual columns it can join them together to create a single three column table.
LET Function.
now the first value we actually want just the date column and since the variable is defining two columns the way I would do it is I would use the index function there's the variable remember that's two columns I want all of the rows comma but only the first column now this is the way I would define that first column and then used to choose to join it to the other two columns but Excel wizard said forget that you just put you now the thing is that's two columns comma when I put you a second time inside of the argument for choose because choose can only match together single columns it can't take what looks like one two and then one two again to create four columns it can only do one column at a time so in essence the second one is sort of a placeholder and we can prove this to ourselves if we just join those two things and entered we can see we get just what we want.
CHOOSE Function
now the interesting thing is and I'm not quite sure why this is working of course if we were to define choose in a silly way just with one of the use it gives us the exact same thing control-z the only thing i can think of is that choose just flat out can only deal with one column at a time so that's how Excel wizard said we should do it because certainly listing those two variables instead of using index twice this is much easier.
Excel Wizard Two Table trick inside CHOOSE.
now the third column of values we create with the sum if spunk we're gonna try and add from the sales column comma criteria range one we're gonna put the whole date column comma and now I need all of these dates from the first column as the condition or criteria to tell some ifs to get the right total for each row so this is where we have to use index on the you to look up just the first column comma we want all the rows but we want the first column close parenthesis now watch this I'm going to cheat them and a copy that because we're gonna use it again come on the criteria range - well we need to look through the product comma control V and here we want to look up the second column and now we come to the end and that is our formula if we close off some ifs close off choose and then close off let so inside this third argument we better comma three so we're telling choose to simultaneously get all three of those columns and when I hit enter that is amazing.
SUMIFS Function
now one thing about dynamic arrays we're always going to have to contend with at least as they've programmed them now everything is grayed out and it may grow or shrink so we need to add conditional formatting and ask the question hey when the cell is not empty please add some formatting home ribbon tab conditional formatting new rule or alt H Ln use a formula to determine which cells to format we can use our mouse or page down we can use our mouse to jump to format values where this formula is true or we can hit tab and we want a relative cell reference so we click once and then the f4 key one two three times and we ask the question are you not equal to a zero link text string that's our syntax for empty cell that we're going to use and then you can add whatever formatting you want add some fill and border click OK and in this column will do currency.
INDEX Function to lookup column.
Conditional Formatting
Add new data and watch report update.
and now when I come over and copy and add new records down below that is amazing we have thanks to Excel wizard a single cell formula to do our reporting.
Summary and End Video Links
all right if you liked that video be sure to click that thumbs up leave a comment and subscribe because there's always lots more videos to come from excel is fun and if you want to learn more about let for dynamic arrays check out these videos.
