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

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)
)

Related

How to extract specific text from a sentence in Excel?

I have a database that exports data like this:
How can I get for instance, the Net Rentable Area with the values needed:
E.G.
Net Rentable Area
I tried the TextSplit function but I got a spill.
Please let me know what can be done, thanks!
Also it would be nice to see it working in something such as the Asking Rate, which has a different format.
In cell C2 you can put the following formula:
=1*TEXTSPLIT(TEXTAFTER(A2, B2&" ")," ")
Note: Multiplying by 1 ensures the result will be a number instead of a text.
and here is the output:
If all tokens to find are all words (not interpreted as numbers), then you can use the following without requiring to specify the token to find:
=LET(split, 1*TEXTSPLIT(A2," "), FILTER(split, ISNUMBER(split)))
Under this assumption you can even have the corresponding array version as follow:
=LET(rng, A2:A100, input, FILTER(rng, rng <>""), IFERROR(DROP(REDUCE(0, input,
LAMBDA(acc,text, LET(split, 1*TEXTSPLIT(text," "),
nums, FILTER(split, ISNUMBER(split),""), VSTACK(acc, nums)))),1),"")
)
Note: It uses the trick for creating multiple rows using VSTACK within REDUCE. An idea suggested by #JvdV from this answer. It assumes A1 has the title of the column, if not you can use A:A instead.

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!

Create IF Formula in MS EXCEL

I am trying to write a formula which states if a value is between X% and Y%, then the text in the cell will read Z.
An example would be if a percentage in cell C4 is between 1% and 39%, then cell D4 should read "Unsatisfactory". Similarly, between 40% and 49% would be "Of Concern", etc.,
The values are:
0% = N/A
1%-39% = Unsatisfactory
40%-49% = Of Concern
50%-64% = Satisfactory
65%-79% = Good
80%-89% = Very Good
90%-100% = Excellent
You will need to use AND together with IF. Something like below should work:
=IF(C4>=90%,"Excellent",
IF(AND(C4&lt90%,C4&gt=80%),"Very Good",
IF(AND(C4&lt80%,C4&gt=65%),"Good",
IF(AND(C4&lt65%,C4&gt=50%),"Satisfactory",
IF(AND(C4&lt50%,C4&gt=40%),"Of Concern",
IF(AND(C4&lt40%,C4&gt=1%),"Unsatisfactory",
"N/A"))))))
The formula goes in D4 as you've mentioned.
Edit1:
As mentioned by Andreas, if you really pay attention to the ordering, you can skip the < part. So above, can be simplified to:
=IF(C4>=90%,"Excellent",
IF(C4>=80%,"Very Good",
IF(C4>=65%,"Good",
IF(C4>=50%,"Satisfactory",
IF(C4>=40%,"Of Concern",
IF(C4>=1%,"Unsatisfactory",
"N/A"))))))
Another way of doing this is to use a lookup table. This can use an array constant inside Lookup like this:
=LOOKUP(A1,{0,1,40,50,65,80,90},{"N/A","Unsatisfactory","Of Concern","Satisfactory","Good","Very Good","Excellent"})
Or Vlookup with a table somwhere in your sheet like this
=VLOOKUP(A2,E$2:F$8,2,TRUE)

Excel - 2 tables - If 2 cells in a single row match, return another cell of same row

Working with 2 separate data sets (with duplicates)
Dataset is unique identified by an ID.
There may not be an entry for the timestamp I require.
Datasets are quite large, and due to duplicates, can't use vlookup.
Samples:
Table 1:
Device Name|Time Bracket| On/Off?
ID1 |06:20:00 |
ID2 |06:20:00 |
ID3 |06:30:00 |
Table 2:
Device Name |Timestamp |On/Off?
ID1 |06:20:00 |On
ID2 |06:50:00 |Off
ID3 |07:20:00 |Off
What I want to achieve:
I want an if statement to check if:
1) device ID matches AND
2) timestamp matches
If so, return the value of On/Off from Table 2.
If not, then I want it to return the value of the cell above it IF it's the same device, otherwise just put "absent" into the cell.
I thought I could do this with some IF statements like so:
=if(HOUR([#[Time Bracket]]) = HOUR(Table13[#[Timestamp Rounded (GMT)]]) and
minute([#[Time Bracket]]) = minute(Table13[#[Timestamp Rounded (GMT)]]) and
[#[Device Name]]=Table13[#[Device Name]], Table13[#[On/Off?]],
IF([#[Device Name]]=Table13[#[Device Name]], INDIRECT("B" and Rows()-1), "absent"))
(I put some newlines in there for readability)
However, this doesn't seem to resolve at all... what am I doing wrong?
Is this even the correct way of achieving this?
I've also tried something similar with a VLookUp, but that failed horribly.
Thanks all!
To not deal with array formulas or merging strings which, (not in your case) can still be wrong at the end, I suggest the use of COUNTIFS due to the fact, you have a very small amount of outcomes (just on or off)...
for the first table (starting at A1, so the formula is at C2):
=IFERROR(CHOOSE(
OR(COUNTIFS(Table13[Device Name],[#[Device Name]],Table13[Timestamp],[#[Time Bracket]],Table13[On/Off?],"On"))+
OR(COUNTIFS(Table13[Device Name],[#[Device Name]],Table13[Timestamp],[#[Time Bracket]],Table13[On/Off?],"Off"))*2
,"On","Off","Error"),IF(A1=[#[Device Name]],C1,"Absent"))
this will also show "Error" of a match for "On" and "Off" is shown... to skip that and increase the speed, you also could use:
=IF(COUNTIFS(Table13[Device Name],[#[Device Name]],Table13[Timestamp],[#[Time Bracket]],Table13[On/Off?],"On"),"On",
IF(COUNTIFS(Table13[Device Name],[#[Device Name]],Table13[Timestamp],[#[Time Bracket]],Table13[On/Off?],"Off"),"Off",
IF(A1=[#[Device Name]],C1,"Absent")))
For both the "Device Name" is at column A, "Time Bracket" at column B and "On/Off?" at column C while the table starts at row 1... If that is not the case for you, then change A1 and C1 so they match
(Also inserted line-breaks for better reading)
Picture to show the layout:
I picked the second formula to show how it works... also, this formula should not be able to return 0's... I'm confused
Couple of good suggestions, however using the helper column as suggested in the topic by Scott Craner above worked.
Created a helper column of concat'd device ID and timestamp for both tables, then did a simple VlookUp.
Another lesson learned: Think outside of the box, and go with simple solutions, rather than try + be too clever like I was doing... :)

excel nested vlookup function using formats and NA Arguments

I placed an example below, of which I don't necessarily 'need' to work, but I don't like that I can't get it to work. I've attempted to use the ISNA function, but am having little success since I
=IF(VLOOKUP(H3,Credit!H:J,3,FALSE)=(J3*-1),"Please Purge",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Not enough Credit... research",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Additional Credit… Research","No Credit Exists")))
I really would like to have a response to each formula, am I using the wrong functions or the wrong format?
To avoid repeating the VLOOKUP function multiple times you can use SIGN and CHOOSE in this scenario like this
=CHOOSE(SIGN(VLOOKUP(H3,Credit!H:J,3,FALSE)+J3)+2,"Not enough Credit... research","Please Purge","Additional Credit… Research")
If you add the VLOOKUP result to J3 you will get a negative number, zero or a positive number, SIGN function will return -1, 0 or 1 respectively for those and then adding 2 gives 1, 2 or 3 so we can use CHOOSE function to convert 1,2 or 3 to the relevant text value
That formula still gives #N/A error if H3 isn't found in Credit!H:H so to avoid that use IFERROR function (assumes Excel 207 or later), so final version becomes:
=IFERROR(CHOOSE(SIGN(VLOOKUP(H3,Credit!H:J,3,FALSE)+J3)+2,"Not enough Credit... research","Please Purge","Additional Credit… Research"),"No credit exists")
perhaps
=IF(ISNA(MATCH(H3,Credit!H:H,0)),"No Credit Exists",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)=(J3*-1),"Please Purge",IF(VLOOKUP(H3,Credit!H:J,3,FALSE)<(J3*-1),"Not enough Credit... research","Additional Credit… Research")))
the MATCH part looks for the value H3 in Credit!H:H and if it isn't there the ISNA handles the resulting error and returns "No credit exists"; the rest is basically just a tweak of the original formula

Resources