Index Match to return MAX Date with multiple criteria - excel

apologies for this, I'm assuming this is simple but a few hours of SO googling hasn't helped
Enough whining from me:
Consider the following dataset:
ID, Date, Review, Review Status
1 01/02/18, "Cool", Positive
1 01/03/18, "Awesome", " Positive
1 01/01/18, "Cumbersome", Negative
1 01/02/18, "Rubbish!", " Negative
I'm currently using an array type index match to get the latest review based on a few conditions
I have two columns one which says positive, one negative.
in each of the column I would like to return the latest positive review but I'm unsure how to get the max date within the below formula:
{=index(C2:C4, MATCH(1,(1 = A2:A4)*("Positive" = D2:D4)*(maxdatehere = B2:B4),0))}
The data I have is around 7k rows and is Google Review Data and pretty much matches the example above.
I'd rather not use VBA as I've never really used it before (but will do so grudgingly)
as this is excel I've not created a google demo sheet, but happy to do so for ease of the experts and for others to benfit if they find there way here one day.

If you have Office 365:
=INDEX(C2:C5, MATCH(1,(1 = A2:A5)*("Positive" = D2:D5)*(MAXIFS(B:B,A:A,1,D:D,"Positive") = B2:B5),0))
Confirme with Ctrl-Shift-enter instead of Enter when exiting edit mode.
If you have 2010 or later then:
=INDEX(C:C,AGGREGATE(15,7,ROW(C2:C5)/((A2:A5=1)*(D2:D5="Positive")*(AGGREGATE(14,7,B2:B5/((A2:A5=1)*(D2:D5="Positive")),1)=B2:B5)),1))
Entered normally.

Related

Excel formula to allow me to retrieve the codes of the most valuables drinks

Good night,
I'm trying to think of a simple excel formula to allow me to get the codes of the most valuables drinks.
I don't wanna use PivotTable for this one.
Ex:
I want to retrieve, for MALIBU, the code 8991
For JAMESON, the code 6113 etc
I'm stuck here since I woke up haha
Thanks!
Try below formula for dynamic spill result-
=LET(x,UNIQUE(C2:C12),y,BYROW(x,LAMBDA(r,INDEX(SORT(FILTER(A2:B12,C2:C12=r),2,-1),1,1))),HSTACK(x,y))
Using MAX function to consider the scenario where more than one code for a given drink can have the maximum value. In cell E2 use the following formula:
=LET(rng, A2:C13, codes, INDEX(rng,,1), values, INDEX(rng,,2),
drinks, INDEX(rng,,3), drinksUx, UNIQUE(drinks),
maxValues, BYROW(drinksUx, LAMBDA(ux,
TEXTJOIN(",",,FILTER(codes, (drinks = ux)
* (values = MAX(FILTER(values, drinks=ux))))))),
HSTACK(drinksUx, maxValues)
)
Here is the output:
Note: Another code for HEINEKEN was added for testing purpose of more than one code with maximum value.
XMATCH can be used for the same purpose too, but it is a more verbose formula:
=LET(rng, A2:C13, codes, INDEX(rng,,1), values, INDEX(rng,,2),
drinks, INDEX(rng,,3),drinksUx, UNIQUE(drinks),
maxValues, BYROW(drinksUx, LAMBDA(ux, TEXTJOIN(",",,
LET(maxValue, MAX(FILTER(values, drinks = ux)),
FILTER(codes, ISNUMBER(XMATCH(drinks & values, ux & maxValue))))))),
HSTACK(drinksUx, maxValues)
)

How can I extract a total count or sum of agents who made their first sale in a specified month?

I am trying to extract some data out of a large table of data in Excel. The table consists of the month, the agent's name, and either a 1 if they made a sale or a 0 if they did not.
What I would like to do is plug in a Month value into one cell, then have it spit out a count of how many agents made their first sale that month.
Sample Data and Input Output area
I found success by creating a secondary table for processing a minif and matching to agent name, then countif in that table's data how many sales months matched the input month. However I would like to not have a secondary table and do this all in one go.
=IF(MINIFS(E2ERawData[Date Group],E2ERawData[Agent],'Processed Data'!B4,E2ERawData[E2E Participation],1)=0,"No Sales",MINIFS(E2ERawData[Date Group],E2ERawData[Agent],'Processed Data'!B4,E2ERawData[E2E Participation],1))
=COUNTIFS(ProcessedData[Month of First E2E Sale],H4)
Formula in column F is:
=MAX(0;COUNTIFS($A$2:$A$8;E3;$C$2:$C$8;1)-SUM(COUNTIFS($A$2:$A$8;"<"&E3;$C$2:$C$8;1;$B$2:$B$8;IF($A$2:$A$8=E3;$B$2:$B$8))))
This is how it works (we'll use 01/03/2022 as example)
COUNTIFS($A$2:$A$8;E3;$C$2:$C$8;1) This counts how many 1 there are for the proper month (in our example this part will return 2)
COUNTIFS($A$2:$A$8;"<"&E3;$C$2:$C$8;1;$B$2:$B$8;SI($A$2:$A$8=E3;$B$2:$B$8)) will count how many 1 you got in previous months of the same agents (in our example, it will return 1)
Result from step 2, because it's an array formula, we sum up using SUM() (in our example, this return 1)
We do result from step 1 minus result from step 3 (so we get 1)
Finally, everything is inside a MAX function to avoid negative results (February would return -1 because there were no sales at all and agent B did a sale on January, so it would return -1. To avoid this, we force Excel to show biggest value between 0 and our calculation)
NOTE: Because it's an array formula, depending on your Excel version maybe you must introduce pressing CTRL+ENTER+SHIFT
If one has got access to the newest functions:
=LET(X,UNIQUE(C3:C9),VSTACK({"Month","Total of First time sales"},HSTACK(X,BYROW(X,LAMBDA(a,SUM((C3:C9=a)*(MINIFS(C3:C9,D3:D9,D3:D9,E3:E9,1)=C3:C9)))))))

Excel: How to find six different combinations of words in string?

I have been working for several days on this and have researched everything looking for this answer. I'd appreciate any help you can give.
In Excel I am searching a string of text in column A:
Bought 1 HD Sep 3 2021 325.0 Call # 2.75
I am detecting the first word (in this case "Bought") and detecting the last word before "#" symbol (in this case "Call").
I am then detecting the price following the "#" symbol (in this case "2.75"). This number will go into column B (header "Open") or column C (header "Close") depending on the combination of words found:
Sold/Put=Close
Sold/Call=Open
Bought/Put=Open
Bought/Call=Close
Sold (by itself)=Open
Sold (by itself)=Close.
Bought 1 HD Sep 3 2021 325.0 Call # 2.75
The combination found in the above string is: "Bought Call". Therefore the number at the end ("2.75"), goes into "Open" column.
Here's another example:
Sold 4 AI Sep 17 2021 50.0 Put # 1.5
The combination found in the above string is: "Sold Put". Therefore the number at the end ("1.5") goes into "Close" column.
I am currently using this formula to determine if the string contains "Sold" and "Call" and get the desired number and it does work:
=IF(AND(
ISNUMBER(SEARCH({"Sold","Call"},A10))),
TRIM(MID(A10,SEARCH("#",A10)+LEN("#"),255))," ")
But, I don't know how to search for all the other possible combinations.
The point behind this is to be able to paste the transaction from the broker and have most of the entry process automated. I'm sure many will benefit from this as I've not found anything like this.
I'd appreciate any help and if possible, an explanation of the formula so I can better learn.
Thanks!
I think you have the right idea, but would just extend the IF statement.
Something like the below might work for you:
=IF(ISNUMBER(SEARCH("Call", $A1)),
IF(ISNUMBER(SEARCH({"Bought","Sold"}, $A1)),
NUMBERVALUE(RIGHT($A1, LEN($A1)-SEARCH("#", $A1))),""),
IF(ISNUMBER(SEARCH({"!!!","!!!","Bought","Sold"}, $A1)),
NUMBERVALUE(RIGHT($A1, LEN($A1)-SEARCH("#", $A1))),""))
Just enter in column B and drag down; columns B through E should fill as needed.
For example:
Note that the search for "!!!" is just random characters, it can be anything that you don't think has a good chance of appearing in the string.
Here/screenshots refer:
(requires Office 365 compatible version Excel)
Main lookup
=LET(fn_1,MATCH("*"&$H$7:$H$12&"*",B4,0),fn_2,MATCH("*"&$I$7:$I$12&"*",B4,0),IFERROR(INDEX($J$7:$J$12,MATCH(1,IF($I$7:$I$12="",fn_1*ISNUMBER(fn_2),fn_1*fn_2),0)),))
EDIT:
Other Excel versions:
=IFERROR(INDEX($J$7:$J$12,MATCH(1,IF($I$7:$I$12="",MATCH("*"&$H$7:$H$12&"*",B4,0)*ISNUMBER(MATCH("*"&$I$7:$I$12&"*",B4,0)),MATCH("*"&$H$7:$H$12&"*",B4,0)*MATCH("*"&$I$7:$I$12&"*",B4,0)),0)),)
(all that falls away is the 'Let' formula, replacing fn_1 and fn_2 with respective functions in index formula within the let making first equation somewhat longer, but otherwise identical)
Example applications
Have provided 2 examples of how one might customize to insert numeric in one of the columns (the key part to this question is really how to do lookup in first instance, from thereon it's a matter of finetuning/taking appropriate action)...
Assuming calls/buys are "long" position and strike price go in first col (here, D), and puts/sales are "short" position with strike price going in 2nd col (here, E):
Long - insert strike price col D
=IF(LET(fn_1,MATCH("*"&$H$7:$H$12&"*",B4,0),fn_2,MATCH("*"&$I$7:$I$12&"*",B4,0),IFERROR(INDEX($K$7:$K$12,MATCH(1,IF($I$7:$I$12="",fn_1*ISNUMBER(fn_2),fn_1*fn_2),0)),))=1,MID(SUBSTITUTE(B4," ",""),SEARCH("#",SUBSTITUTE(B4," ",""))+1,LEN(SUBSTITUTE(B4," ",""))),"")
EDIT
Other Excel versions:
=IF(IFERROR(INDEX($K$7:$K$12,MATCH(1,IF($I$7:$I$12="",MATCH("*"&$H$7:$H$12&"*",B4,0)*ISNUMBER(MATCH("*"&$I$7:$I$12&"*",B4,0)),MATCH("*"&$H$7:$H$12&"*",B4,0)*MATCH("*"&$I$7:$I$12&"*",B4,0)),0)),)=1,MID(SUBSTITUTE(B4," ",""),SEARCH("#",SUBSTITUTE(B4," ",""))+1,LEN(SUBSTITUTE(B4," ",""))),"")
Short - insert strike price col E
=IF(LET(fn_1,MATCH("*"&$H$7:$H$12&"*",B4,0),fn_2,MATCH("*"&$I$7:$I$12&"*",B4,0),IFERROR(INDEX($K$7:$K$12,MATCH(1,IF($I$7:$I$12="",fn_1*ISNUMBER(fn_2),fn_1*fn_2),0)),))=2,MID(SUBSTITUTE(B4," ",""),SEARCH("#",SUBSTITUTE(B4," ",""))+1,LEN(SUBSTITUTE(B4," ",""))),"")
EDIT
Other Excel versions:
Follow same routine in previous Edits (remove Let, replace fn_1 & fn_2 with respective formulae...)
Note similarity in all 3 equations above: 2nd and 3rd contain 1st (effectively they just wrap a big old 'if' statement around 1st, use lookup_2 col (here, col K), and use mid/search to extract rate after the hashtag.
Assumes you don't have other hashtags in the sentence..
Customize as required.

Excel CUBEVALUE & CUBESET count records greater than a number

I am writing a series of queries to my workbook's data model to retrieve the number of documents by Category_Name which are greater than a certain numbers of days old (e.g. >=650).
Currently this formula (entered in celll C3) returns the correct number for a single Days Old value (=3).
=CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]",
"[EDD_Report_10-01-18].[Days Old].[34]")
How do I return the number of documents for Days Old values >=650?
The worksheet looks like:
A B C
1 Date PL Count of Docs
2 10/1/2018 ALD 3
3 ...
UPDATE: As suggested in #ama 's answer below, the expression in step B did not work.
However, I created a subset of the Days Old values using
=CUBESET("ThisWorkbookDataModel",
"{[EDD_Report_10-01-18].[Days Old].[all].[650]:[EDD_Report_10-01-18].[Days Old].[All].[3647]}")
The cell containing this cubeset is referenced as the third Member_expression of the original CUBEVALUE formula. The limitation is now that the values for the beginning and end must be members of the Days Old set.
This is limiting, in that, I was hoping for a more general test for >=650 and there is no way to guarantee that specific values of Days Old will be in the query.
First time I hear about CUBE, so you got me curious and I did some digging. Definitely not an expert, but here is what I found:
MDX language should allow you to provide value ranges in the form of {[Table].[Field].[All].[LowerBound]:[Table].[Field].[All].[UpperBound]}.
A. Get the total number of entries:
D3 =CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]"),
"{[EDD_Report_10-01-18].[Days Old].[All]")
B. Get the number of entries less than 650:
E3 =CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]"),
"{[EDD_Report_10-01-18].[Days Old].[All].[0]:[EDD_Report_10-01-18].[Days Old].[All].[649]}")
Note I found something about using .[All].[650].lag(1)} but I think for it to work properly your data might need to be sorted?
C. Substract
C3 =D3-E3
Alternatively, go for the quick and dirty:
=CUBEVALUE("ThisWorkbookDataModel",
"[Measures].[Count of Docs]",
"[EDD_Report].[Category_Name].&["&$B2&"]"),
"{[EDD_Report_10-01-18].[Days Old].[All].[650]:[EDD_Report_10-01-18].[Days Old].[All].[99999]}")
Hope this helps and do let me know, I am still curious!

Moving total which uses two calculated fields and also uses its previous value-Spotfire

Hi folks I am new to Spotfire and having difficulty in replicating one of the formulas from Excel to spotfire.
Sample Data
Sample data here(excel)
https://docs.google.com/spreadsheets/d/1KSdrIYKlRYG9c3wIM3NwQcLP_Ob8Z2UZ5Cjrdjy8UO8/edit?usp=sharing
and I am trying to replicate the column [Steady Repay-Option Scenario]
Formula used in excel
=IF(B6-IF(C3>0,C2,0)>0,B6-IF(C3>0,C2,0),0)
the above is the formula I have in excel where subsequent columns are calculated by using the previous value and the current values from columns [Monthly impact on cash] and [running total]
This is the formula I have created in spotfire:
if((Sum([Scenario opening balance]) over (allPrevious([Document_Date_Number])) - (If(Sum([Rolling_total_cash_calculated]) over (AllPrevious([Document_Date_Number]))>0,Sum([Monthly_impact_on_cash_calculated]) over (AllPrevious([Document_Date_Number])),0)))>0,Sum([Scenario opening balance]) over (allPrevious([Document_Date_Number])) - (If(sum([Rolling_total_cash_calculated]) over (allPrevious([Document_Date_Number]))>0,Sum([Monthly_impact_on_cash_calculated]) OVER (allPrevious([Document_Date_Number])),0)),0)
Assumptions--
Data has been pivoted into three columns([Document_Date_Number], Monthly_impact_on_cash_calculated] and [Rolling_total_cash_calculated])
where:
[Scenario opening balance] = 150000000(fixed)
[Document_Date_Number] = Jan,Feb,Mar etc
[Rolling_total_cash_calculated] = Rolling total(excel)
[Monthly_impact_on_cash_calculated] = Monthly impact on cash(excel)
But I get incorrect results for some reason
results in spotfire
But the expected result is
Correct result in excel
So although the results match till Oct as shown above they don't seem to match afterwards.
Please let me know what can I do to get the same values. Any help in deeply appreciated.

Resources