User Profile
djclements
Bronze Contributor
Joined 2 years ago
User Widgets
Recent Discussions
Re: Additional help needed with existing formula using LAMDA- Excel 365
The problem is in column E (GOAL) on the RESULTS worksheet in your 082625 stripped-down file. It's not visibly obvious because the results are hidden from view (via conditional formatting) when column D="N/A". If you remove the formatting, you'll see the formulas in column E are returning #VALUE! errors when column D="N/A". Your original 061625 sample file had a different formula in this column that worked properly. Either restore the original formula, or try the following in cell E5 (and copy down): =IFS(D5="n/a","",D5<F5,"NOT MET",D5>G5,"EXCEED",1,"MET") Once this is corrected, you should be able to successfully implement ANY of the methods I've suggested thus far. If you need help tweaking anything else thereafter, just let me know.40Views1like0CommentsRe: Additional help needed with existing formula using LAMDA- Excel 365
I reorganized the sample file, so each table now contains the same number of columns, in the same order, as the updated SheetMap. The only thing I had to change about the formula (from rev3.0) was the _cId variable to set the field mapping: =LET( _rep, RESULTS!$A$2, _beg, RESULTS!$B$2, _end, RESULTS!$C$2, _lst, RESULTS!$A$5:$A$12, _inc, (RESULTS!$E$5:$E$12="EXCEED")+(RESULTS!$E$5:$E$12="NOT MET"), IF( NOT(OR(_inc)), "[no records found]", LET( VALλ, LAMBDA(lbl,tId,csv,LAMBDA(x,CHOOSE(x,lbl,tId,csv))), EXPλ, LAMBDA(array,[rws],EXPAND(array,rws,9,"")), INCλ, LAMBDA(field3,field2,(field3=_rep)*(field2>=_beg)*(field2<=_end)), _fId, SEQUENCE(,9), _cId, VSTACK("1,2,3,4,,,5,13,14", "1,2,3,4,,6,5,10,11", "1,2,3,4,,,5,11,12", "1,2,3,4,6,,,8,9", "1,2,3,4,,,5,11,12", "1,2,3,4,7,6,5,12,13", "1,2,3,4,6,,5,14,15", "1,2,3,4,6,7,8,14,19"), REDUCE( EXPλ("Field"&_fId,2), FILTER(MAP(_lst,SEQUENCE(ROWS(_lst)),_cId,VALλ),_inc), LAMBDA(acc,val, LET( tbl, INDIRECT("tbl"&SUBSTITUTE(SUBSTITUTE(val(1)," ",),"-",)&"[#ALL]"), arr, SORTBY(EXPλ(CHOOSECOLS(tbl,--TEXTSPLIT(val(3),",",,1))),SORTBY(_fId,TEXTSPLIT(val(3),",")="")), bdy, DROP(arr,1), qry, FILTER(bdy,INCλ(CHOOSECOLS(bdy,3),CHOOSECOLS(bdy,2))), VSTACK(acc,EXPλ("["&val(2)&"] "&val(1)&":"),EXPλ(TAKE(arr,1)),EXPλ(IF(ISBLANK(qry),"",qry),ROWS(qry)+1)) ) ) ) ) ) ) I also added a 'FieldMap' worksheet to the attached revision, so you can see how the field mapping was generated (there are 4 formulas highlighted in blue, as well as a note showing the formula used as the Data Validation List Source for range C5:U12). If you're still having issues applying these methods to your master workbook, I'm afraid there's not much more I can do to help aside from gaining access to your actual workbook to troubleshoot the problem. Best of luck!15Views1like1CommentRe: Additional help needed with existing formula using LAMDA- Excel 365
Hi Marcus, If the order of the table columns has changed, that could be causing some issues, although it may or may not be the source of the #VALUE! error. However, if the total number of columns in each table has changed, that could be the reason. For example, the SheetMap shows only 13 columns in the Claims table, whereas the sample file contains 14 columns, so using =CHOOSECOLS(tblClaims,14) will return #VALUE! if column 14 no longer exists (out of scope reference). It would also be helpful if you could provide the column names (table headers) in the SheetMap (it currently only shows the column index numbers). Try using the following formula to generate a complete list, then Copy the results and Paste Special > Values into the SheetMap workbook: =LET( i, SEQUENCE(SHEETS(Claims:RESEA!A1)), j, SEQUENCE(,COLUMNS(A1:Z1)), HSTACK(TOCOL(IF(j,i)),TOCOL(IF(i,j)),TOCOL(Claims:RESEA!A1:Z1)) ) Please include all results, even those that return 0's for fields that don't exist, so I'll be able to easily identify exactly what's been changed (number of columns, column names and order). Kind regards.51Views1like3CommentsRe: Additional help needed with existing formula using LAMDA- Excel 365
It's not likely to be related to the other tabs/worksheets in your master workbook, as the formula is only referencing cells/ranges in the 'RESULTS' tab directly. The INDIRECT function is being used to reference tables in the workbook, but the syntax for this is the same as what was already working in your original sample workbook(s), so that wouldn't explain it. I saw your comment on the previous thread, where you confirmed "The master workbook is named differently and contains more tabs than the redacted (included here) spreadsheet, but all of the table names and column headers are the same.", so there shouldn't be any issues when copying the formula over. However, I also noticed there was a bit of a struggle to get any of the suggested formulas on that thread to work, and a considerable amount of time was spent troubleshooting this. To transfer the formula from the sample workbook to your master workbook, highlight the entire formula from within the formula bar in the sample workbook and press Ctrl+C to copy, then select the destination cell in your master workbook, click into the formula bar (delete any previous formula, if applicable) and press Ctrl+V to paste. #VALUE! errors can be difficult to track down, but it usually means there is an issue with one or more of the data types used. For example, =10+"text" will return this error because the addition operator is expecting two numbers (type 1) but received a text string (type 2). =TAKE(A1:A5,{3}) will also error because the rows argument is expecting a scalar (type 1) but received an array (type 64). I've reviewed my formula and don't see anything out of place. Even if there was, it wouldn't explain why the formula works in the sample workbook but not in the master workbook. Having said that, I'm not really a fan of how the current "working" formula outputs the report. There's a different number of columns being selected from each table, and the field order is different between tables. The end result is a bit of a mess, where only the first 3 columns are identical across all 8 tables, and the rest are a mix-match of data types. This makes formatting dates virtually impossible, as fields like "Date Processed" and "Date Reconsidered" are appearing in the same columns as numeric fields like "PID" and "Issue Number". Another option is to use something of a field-mapping table to link compatible fields and output them to the same column. For example: =LET( _rep, RESULTS!$A$2, _beg, RESULTS!$B$2, _end, RESULTS!$C$2, _lst, RESULTS!$A$5:$A$12, _inc, (RESULTS!$E$5:$E$12="EXCEED")+(RESULTS!$E$5:$E$12="NOT MET"), IF( NOT(OR(_inc)), "[no records found]", LET( VALλ, LAMBDA(lbl,tId,csv,LAMBDA(x,CHOOSE(x,lbl,tId,csv))), EXPλ, LAMBDA(array,[rws],EXPAND(array,rws,9,"")), INCλ, LAMBDA(field3,field2,(field3=_rep)*(field2>=_beg)*(field2<=_end)), _fId, SEQUENCE(,9), _cId, VSTACK("1,2,3,4,,,5,13,14", "1,2,3,4,,5,6,10,11", "1,2,3,4,,,5,11,12", "1,2,3,4,5,,,7,8", "1,2,3,4,,,5,11,12", "1,2,3,5,7,6,4,12,13", "1,2,3,4,5,,6,14,15", "1,2,3,4,5,6,7,13,18"), REDUCE( EXPλ("Field"&_fId,2), FILTER(MAP(_lst,SEQUENCE(ROWS(_lst)),_cId,VALλ),_inc), LAMBDA(acc,val, LET( tbl, INDIRECT("tbl"&SUBSTITUTE(SUBSTITUTE(val(1)," ",),"-",)&"[#ALL]"), arr, SORTBY(EXPλ(CHOOSECOLS(tbl,--TEXTSPLIT(val(3),",",,1))),SORTBY(_fId,TEXTSPLIT(val(3),",")="")), bdy, DROP(arr,1), qry, FILTER(bdy,INCλ(CHOOSECOLS(bdy,3),CHOOSECOLS(bdy,2))), VSTACK(acc,EXPλ("["&val(2)&"] "&val(1)&":"),EXPλ(TAKE(arr,1)),EXPλ(IF(ISBLANK(qry),"",qry),ROWS(qry)+1)) ) ) ) ) ) ) The width of the output array in this example is fixed (9 columns). _cId is where the field-mapping is set for each table, and arr is where the field-mapping is applied (using SORTBY-TEXTSPLIT). This will output numeric fields like "PID" and "Issue Number" in Field5, and all date fields in Field7, making them easier to format: Furthermore, if you're always dealing with the same 8 tables, it's also possible to eliminate the INDIRECT function by utilizing a custom CHOOSE based lambda function to select each table as needed. For example: =LET( _rep, RESULTS!$A$2, _beg, RESULTS!$B$2, _end, RESULTS!$C$2, _lst, RESULTS!$A$5:$A$12, _inc, (RESULTS!$E$5:$E$12="EXCEED")+(RESULTS!$E$5:$E$12="NOT MET"), IF( NOT(OR(_inc)), "[no records found]", LET( VALλ, LAMBDA(lbl,tId,csv,LAMBDA(x,CHOOSE(x,lbl,tId,csv))), EXPλ, LAMBDA(array,[rws],EXPAND(array,rws,9,"")), INCλ, LAMBDA(field3,field2,(field3=_rep)*(field2>=_beg)*(field2<=_end)), TBLλ, LAMBDA(table_id,CHOOSE(table_id, tblClaims[#All],tblMiscAssignments[#All],tblProcessProtest[#All],tblIDD[#All], tblProcessAppeal[#All],tblDPU[#All],tblVetRRVDVOP[#All],tblRESEA[#All])), _fId, SEQUENCE(,9), _cId, VSTACK("1,2,3,4,,,5,13,14", "1,2,3,4,,5,6,10,11", "1,2,3,4,,,5,11,12", "1,2,3,4,5,,,7,8", "1,2,3,4,,,5,11,12", "1,2,3,5,7,6,4,12,13", "1,2,3,4,5,,6,14,15", "1,2,3,4,5,6,7,13,18"), REDUCE( EXPλ("Field"&_fId,2), FILTER(MAP(_lst,SEQUENCE(ROWS(_lst)),_cId,VALλ),_inc), LAMBDA(acc,val, LET( tbl, TBLλ(val(2)), arr, SORTBY(EXPλ(CHOOSECOLS(tbl,--TEXTSPLIT(val(3),",",,1))),SORTBY(_fId,TEXTSPLIT(val(3),",")="")), bdy, DROP(arr,1), qry, FILTER(bdy,INCλ(CHOOSECOLS(bdy,3),CHOOSECOLS(bdy,2))), VSTACK(acc,EXPλ("["&val(2)&"] "&val(1)&":"),EXPλ(TAKE(arr,1)),EXPλ(IF(ISBLANK(qry),"",qry),ROWS(qry)+1)) ) ) ) ) ) ) TBLλ is the lambda function that contains the references to each table, and TBLλ(val(2)) is where each table is recalled (replacing the INDIRECT function). I've also used a custom VALλ function here to make referencing the variables easier (replacing the INDEX function). Please note, many of the variables and functions used in these examples can be defined in Name Manager, which would make the end formula shorter and easier to write. However, I refrained from doing so to make it as easy as possible for you to transfer the formula to your master workbook. If you're still experiencing issues and want to send me a copy of your master workbook in a private message (go to my profile page and click "Message"), I'll be happy to troubleshoot it for you. Cheers!0Views1like6CommentsRe: Additional help needed with existing formula using LAMDA- Excel 365
Did you download the attached file, and it shows #VALUE! immediately after opening it? Or did you just copy/paste the formula from my post directly into your master workbook? And if so, did you make sure all of the sheet/range references are pointing to the correct cells in your master workbook? The formula works fine for me, even if I copy/paste it into any one of your sample files from the original thread. Differences in Regional and Language settings can sometimes affect the syntax, so it's best if you download the workbook I shared and try copying the formula from there. Kind regards.102Views1like0CommentsRe: Additional help needed with existing formula using LAMDA- Excel 365
Try the following revision and see if it meets your needs: =LET( _rep, RESULTS!A2, _beg, RESULTS!B2, _end, RESULTS!C2, _inc, (RESULTS!E5:E12="EXCEED")+(RESULTS!E5:E12="NOT MET"), IF( NOT(OR(_inc)), "[no records found]", LET( keys, FILTER(HSTACK(RESULTS!A5:A12,VSTACK(5,6,5,5,5,7,6,7)),_inc), cols, MAX(DROP(keys,,1))+2, EXPλ, LAMBDA(array,[rws],EXPAND(array,rws,cols,"")), INCλ, LAMBDA(field3,field2,(field3=_rep)*(field2>=_beg)*(field2<=_end)), REDUCE( EXPλ("REPORT:"), SEQUENCE(ROWS(keys)), LAMBDA(acc,rId, LET( lbl, INDEX(keys,rId,1), tbl, INDIRECT("tbl"&SUBSTITUTE(SUBSTITUTE(lbl," ",),"-",)&"[#ALL]"), arr, HSTACK(TAKE(tbl,,INDEX(keys,rId,2)),TAKE(tbl,,-2)), bdy, DROP(arr,1), qry, FILTER(bdy,INCλ(INDEX(bdy,,3),INDEX(bdy,,2))), VSTACK(acc,EXPλ("["&rId&"] "&lbl&":"),EXPλ(TAKE(arr,1)),EXPλ(IF(ISBLANK(qry),"",qry),ROWS(qry)+1)) ) ) ) ) ) ) See attached, if needed... EDIT: added an optional [rws] argument to the EXPλ function so the qry results can be expanded by 1 row to separate each table in the final output.18Views1like0CommentsRe: Stacking The Beatles in Excel: An Exercise in 3D stacking
Interesting concept, passing the entire table as the first and only required argument, then unpivoting based on the optional arguments provided. Definitely looks doable as a lambda function. I have a couple of custom functions already that I use for basic unpivots. The first one automatically removes blanks and errors, which is the most common request: =LAMBDA(row_fields,col_labels,values,[scan_by_col], LET( tst, values<>"", fnλ, LAMBDA(arr,TOCOL(IFS(tst,arr),2,scan_by_col)), HSTACK( CHOOSEROWS(row_fields,fnλ(SEQUENCE(ROWS(row_fields)))), CHOOSEROWS(TRANSPOSE(col_labels),fnλ(SEQUENCE(,COLUMNS(col_labels)))), fnλ(values) ) ) ) Set the optional [scan_by_col] argument to 1 or TRUE to change the output order. The second one has the option to remove blanks and errors as desired: =LAMBDA(row_fields,col_labels,values,[ignore],[scan_by_col], LET( v, TOCOL(values,,scan_by_col), a, HSTACK( INDEX(row_fields,TOCOL(IFNA(SEQUENCE(ROWS(row_fields)),values),,scan_by_col),SEQUENCE(,COLUMNS(row_fields))), INDEX(col_labels,SEQUENCE(,ROWS(col_labels)),TOCOL(IFNA(SEQUENCE(,COLUMNS(col_labels)),values),,scan_by_col)),v), CHOOSE(ignore+1,a,FILTER(a,NOT(ISBLANK(v))),FILTER(a,NOT(ISERROR(v))),FILTER(a,NOT(ISBLANK(v)+ISERROR(v)))) ) ) The optional [ignore] argument accepts the same choices as that of TOCOL/TOROW: 0 - Keep all values (default) 1 - Ignore blanks 2 - Ignore errors 3 - Ignore blanks and errors Both methods can handle multiple columns of row_fields, as well as multiple rows of col_labels. In most cases I'm not too worried about headers as they're pretty easy to input/stack manually and customize on your own. If you wanted to get cute, though, and include an option for headers, it could look something like this: =LAMBDA(row_fields,col_labels,values,[scan_by_col],[headers], LET( tst, values<>"", fnλ, LAMBDA(arr,TOCOL(IFS(tst,arr),2,scan_by_col)), pvt, HSTACK( CHOOSEROWS(row_fields,fnλ(SEQUENCE(ROWS(row_fields)))), CHOOSEROWS(TRANSPOSE(col_labels),fnλ(SEQUENCE(,COLUMNS(col_labels)))), fnλ(values) ), IF( TYPE(headers)=64, VSTACK(headers,pvt), IF( headers, VSTACK(HSTACK("Field"&SEQUENCE(,COLUMNS(row_fields)),"Attribute"&SEQUENCE(,ROWS(col_labels)),"Value"),pvt), pvt ) ) ) ) The optional [headers] argument would then accept the following: 0 or FALSE - None (default) 1 or TRUE - Auto-generate A horizontal array of custom headers, e.g. {"first","last","attribute","value"} For example: =Unpivotλ(A3:B5,C1:H2,C3:H5,TRUE,{"First","Last","Fiscal Year","Month","Commissions"}) More advanced scenarios involving multiple value fields (e.g. Sales and Commissions) can get kind of hairy, so I just end up writing tailored solutions on a case-by-case basis for those situations.0Views2likes1CommentRe: Stacking The Beatles in Excel: An Exercise in 3D stacking
Well done! I've been doing a lot of table transformations with INDEX-SEQUENCE algorithms recently, so I took a crack at it: =LAMBDA(ref_3d, LET( a, HSTACK(ref_3d), b, TAKE(a,1), h, ROWS(a)-1, w, COLUMNS(a), m, SHEETS(ref_3d), n, w/m, k, SEQUENCE(h*m,,0), x, DROP(SORTBY(a,QUOTIENT(SEQUENCE(,w,0),n),1,b,1),1), y, INDEX(x,MOD(k,h)+1,QUOTIENT(k,h)*n+SEQUENCE(,n)), VSTACK(UNIQUE(SORT(b,,,1),1),FILTER(y,TAKE(y,,1)<>"")) ) ) It's a little longer, but should hold up well performance-wise. If any one of the worksheets were missing a field, though, I think an unpivot-repivot method might be the way to go. Something like: =LET( a, HSTACK(Albums3D), b, DROP(a,1), w, COLUMNS(a), i, SEQUENCE(ROWS(b)), j, QUOTIENT(SEQUENCE(,w,0),w/SHEETS(Albums3D)), t, b<>"", f, LAMBDA(x,TOCOL(IFS(t,x),2)), DROP(PIVOTBY(HSTACK(f(j),f(i)),f(TAKE(a,1)),f(b),SINGLE,0,0,,0),,2) ) Or: =LET( a, HSTACK(Albums3D), b, DROP(a,1), v, TOCOL(b), w, COLUMNS(a), i, SEQUENCE(ROWS(b)), j, QUOTIENT(SEQUENCE(,w,0),w/SHEETS(Albums3D)), f, LAMBDA(x,TOCOL(IF({1},x,b))), DROP(PIVOTBY(HSTACK(f(j),f(i)),f(TAKE(a,1)),v,SINGLE,0,0,,0,,v<>""),,2) ) I'm not really sure if there's any difference in efficiency between the two. I'd like to think the second one is faster because it removes the blank records in one swoop with the [filter_array] argument of PIVOTBY, whereas the first method removes the blank records for every instance of TOCOL (4 times), but I didn't run any tests with larger datasets. Cheers!3Views2likes3CommentsRe: Shift cells up
A formula approach: =WRAPROWS(TOCOL(_0xB8D8_Log_Study_Sample,1),3) Or Power Query: let Source = Excel.CurrentWorkbook(){[Name="_0xB8D8_Log_Study_Sample"]}[Content], #"Filled Down" = Table.FillDown(Source,{"Custom", "Custom.1"}), #"Filtered Rows" = Table.SelectRows(#"Filled Down", each ([Custom.2] <> null)) in #"Filtered Rows"210Views3likes1CommentRe: Wider Excel discussion
Agreed: a built-in EVALTHUNKARRλ function would be ideal. The STYLE concept would also be neat, if they could pull it off. Perhaps something akin to CSS, where you define and apply your own custom styles? Sounds like Pivot Tables are getting an "Auto-Refresh" option, which is long overdue. GROUPBY and PIVOTBY are great, but difficult to format (they also lack basic options like choosing to "insert blank line after each item label" or to NOT "repeat item labels"). I tend to use them more as an intermediary step for solving larger problems, rather than the final output. It would be super helpful if Conditional Formatting rules could be applied to a dynamic spill range. 😏76Views0likes0CommentsRe: Wider Excel discussion
My biggest pet peeve is that DROP-REDUCE-VSTACK and MAKEARRAY-INDEX are still the most commonly suggested dynamic array methods found on any Excel forum. I too was initially drawn to them when I made the switch to Office 365, as the logic is very similar to a For Each / For Next loop in VBA. Fortunately, David Leal was kind enough to advise me very early on about their efficiency issues, and I've been actively seeking out and sharing alternative methods ever since. It feels like a losing battle, though, as everywhere I turn it's DROP-REDUCE-VSTACK and MAKEARRAY-INDEX over and over again... Not sure if that's what you meant by "low-grade material", but they're definitely "low-grade" in my book. Your custom MAPλ and EVALTHUNKARRλ functions are still the best generic alternatives I've come across to date. ;)134Views0likes6CommentsRe: Sumifs or other solution for both vertical & horizontal criteria
GROUPBY on both axes is also a potential option here: =LET( Nz, LAMBDA(x,IF(ISBLANK(x),"",x)), y, TRANSPOSE(VSTACK(Nz(A3:F3),GROUPBY(Nz(A4:A8),B4:F8,SUM,3,0))), TRANSPOSE(GROUPBY(TAKE(y,,2),DROP(y,,2),SUM,3,0)) )65Views1like0CommentsRe: Dynamically filter table on basis of range of criteria
Not 100% sure what type of criteria you wanted because "it should be an AND filter so the column should contain any of these words" is somewhat contradictory. "Any of these words" suggests OR criteria, whereas "all of these words" would mean AND criteria. If you have the new REGEXTEST function, you could try the following using OR criteria: =CHOOSECOLS(FILTER(Table3[[SuppliersTradeItemId]:[GrossPrice]],REGEXTEST(Table3[Description],TEXTJOIN("|",,Table4[Criteria]))),1,2,-1) Also, using AND criteria: =CHOOSECOLS(FILTER(Table3[[SuppliersTradeItemId]:[GrossPrice]],BYROW(REGEXTEST(Table3[Description],TOROW(Table4[Criteria],1)),AND)),1,2,-1) There's a good video on YouTube, Excel Filter Function With RegexTest Function, which includes various other examples; however, no explanation was offered for using AND criteria... the formula shown above was the best I could figure it, utilizing BYROW-AND over an array of patterns. If someone else knows of a better way, I'd love to hear it.39Views0likes0CommentsRe: Create table using LET based on column values
Another basic unpivot option: =LET( v, H3:U16, t, v<>"", λ, LAMBDA(x,TOCOL(IFS(t,x),2)), a, INDEX(A3:G16,λ(SEQUENCE(ROWS(v))),{1,2,4,3,6,7}), HSTACK(TAKE(a,,4),λ(H2:U2),DROP(a,,4),λ(v)) ) Adjust the 3 range references as needed. See attached...90Views1like0CommentsRe: Summarize multiple columns of varying row lengths into one column.
Another approach, using the TOCOL-IFS method: =LET( rng, TRIMRANGE(A3:K10000,2,0), val, FILTER(DROP(rng,1),TAKE(rng,1)="Analyte"), tst, val<>"", fnλ, LAMBDA(arr,TOCOL(IFS(tst,arr),2)), key, fnλ(SCAN("",TAKE(DROP(rng,1),,1),LAMBDA(a,v,IF(v="",a,v)))), SORTBY(HSTACK(IF(key=DROP(VSTACK("",key),-1),"",key),fnλ(val)),key,1,fnλ(SEQUENCE(,COLUMNS(val))),1) ) See attached, if needed...54Views1like0CommentsRe: Table Merge from Web
When you first select the desired tables to be imported, click the drop-down arrow beside "Load" and select "Load To...", then select "Only Create Connection" and click "OK". If you've already imported these tables into your workbook, go to Data > Queries and Connections, right-click on each table query, select "Load To..." and change it to "Only Create Connection". After all of the desired tables have been imported as "Connection only", go to Data > Get Data > Launch Power Query Editor..., select the first table query in the left-hand pane, then go to Home > Append Queries > Append Queries as New and add the applicable tables to append. From there you can modify the query as needed to clean the data, then "Close and Load" to a table in the workbook. Please see the attached sample file, if needed...32Views0likes1CommentRe: Excel Sumifs
ShellarC The only issue was, in your sample table, all "Units" amounts were entered as positive numbers, so all solutions were written to subtract "Sold" from "Bought"; however, in your actual Stocks.xlsx data table, "Sold" amounts were entered as negative numbers. Simply modify any one of the suggested formulas to add "Sold" to "Bought" instead of subtracting. The GROUPBY method also becomes significantly easier: =LET( grp, GROUPBY(M[Ticker],M[Units],SUM,0,0), FILTER(grp,TAKE(grp,,-1)>0) ) Or, to include stocks with a negative balance: =LET( grp, GROUPBY(M[Ticker],M[Units],SUM,0,0), FILTER(grp,TAKE(grp,,-1)) ) Also, I noticed the "Trans" column contains some "Dividend" entries (aside from just "Bought" and "Sold"). If these entries were to have amounts in the "Units" column that needed to be excluded, you can filter them out using the optional [filter_array] argument: =LET( grp, GROUPBY(M[Ticker],M[Units],SUM,0,0,,M[Trans]<>"Dividend"), FILTER(grp,TAKE(grp,,-1)>0) ) Cheers!95Views1like0CommentsRe: Excel Sumifs
This is just a variation of what's already been shared: =LET( tkr, UNIQUE(SORT(M[Ticker])), amt, LAMBDA(trn,SUMIFS(M[Units],M[Ticker],tkr,M[Trans],trn)), net, amt("Bought")-amt("Sold"), FILTER(HSTACK(tkr,net),net) ) Adjust the table/field names as needed. (EDIT: I already adjusted the table name to "M", so it will work with your Stocks.xlsx file.) A couple of tips/comments: the UNIQUE function is significantly faster when the array is sorted first, so it's best to use UNIQUE-SORT instead of SORT-UNIQUE. to remove zeros from an array of numeric values, just pass the array to the include argument of the FILTER function... there is no need to perform a logical comparison, such as net<>0, because zeros are already interpreted as FALSE, and all other numeric values are interpreted as TRUE.91Views0likes0CommentsRe: Dynamic Calendar in Excel 365
DaeyunPablo Better late than never... I revisited this today with improved methods, which can handle a date range spanning hundreds of years efficiently: =LET( wrap_count, 3, low, MIN(B7:B15), upp, MAX(B7:B15), num, CEILING.MATH((YEAR(upp) - YEAR(low)) * 12 + MONTH(upp) - MONTH(low) + 1, wrap_count), beg, DATE(YEAR(low), MONTH(low) + SEQUENCE(num,, 0), 1), pad, EXPAND("", ROWS(beg), 3, ""), lbl, EXPAND(TEXT(beg, "mmm-e"),, 4, ""), hdr, IFNA(TEXT(SEQUENCE(, 7), "ddd"), beg), bdy, beg - WEEKDAY(beg) + SEQUENCE(, 42), arr, HSTACK(pad, lbl, hdr, (MONTH(bdy) = MONTH(beg)) * bdy), h, 8, w, 7, n, wrap_count * w, i, SEQUENCE(COUNTA(arr) / n,, 0), j, SEQUENCE(, n, 0), INDEX(arr, 1 + QUOTIENT(j, w) + wrap_count * QUOTIENT(i, h), 1 + MOD(j, w) + w * MOD(i, h)) ) Adjust the wrap_count as desired. Cheers!57Views1like0CommentsRe: Spilled formula calculating revenue by quater or year
Perhaps something along these lines: =LET( i, IF(tbl_Projecten[Duration],tbl_Projecten[Duration],1), j, SEQUENCE(,MAX(i),0), t, i>j, p, TOCOL(IFS(t,tbl_Projecten[Project]),2), v, TOCOL(IFS(t,tbl_Projecten[Revenues]/i),2), d, TOCOL(IFS(t,EDATE(+tbl_Projecten[Startdate],j)),2), q, QUOTIENT(MONTH(d)-1,3)+1, y, YEAR(d), a, PIVOTBY(HSTACK(y,q),p,v,SUM,0,2,,1), VSTACK(HSTACK({"Year","Quarter"},DROP(TAKE(a,1),,2)),DROP(a,1)) ) See also the Conditional Formatting rules in the attached file...136Views2likes1Comment
Recent Blog Articles
No content to show