SUMIFS with Substring - string

I'm using SUMIFS function to compute commissions based on invoice data. One of the fields I need to check has a product code with many meanings based on position of the data within the code.
For example, product code of "NCH - R - OTF - CH" indicates owner of product is NCH, R meaning Retail, OTF meaning Off the Shelf, and CH meaning commission on Chinese Herbs.
I need to add additional condition in my current SUMIFs function to check if the product code in column “D” has commission code of "CH". I need to only check the last two characters of the product item code.
=SUMIFS('Invoice Items'!$M$2:$M$30000,'Invoice Items'!$F$2:$F$30000,"Product",'Invoice Items'!$A$2:$A$30000,"=Paid")

You can add
'Invoice Items'!$D$2:$D$30000, "*CH"
as a set of criteria to SUMIFS
it will look like:
=SUMIFS('Invoice Items'!$M$2:$M$30000,'Invoice Items'!$F$2:$F$30000,"Product",'Invoice Items'!$A$2:$A$30000,"=Paid",'Invoice Items'!$D$2:$D$30000, "*CH")

Related

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 return true if number is within range

My problem
I have a list of values (List 1) that have the following pattern...
1234-COD-125
I have another list (List 2), which follow the pattern...
12345(1234-COD-100 - 1234-COD-150)
I need to search List 2 and return True if the value in List 1 is within range. So for example..
List 1 Result List 2
1234-COD-125 TRUE 12345(1234-COD-100 - 1234-COD-150)
1234-COD-126 TRUE 12345(4567-BAH-100 - 4567-BAH-150)
1234-COD-155 FALSE
4567-BAH-125 TRUE
4567-BAH-126 TRUE
4567-BAH-155 FALSE
Background
The first part (1234-COD) is the vendor ID and code. The last part (125) is the order ID. Different vendors can have the same order ID, so my lookup needs to account for the vendor.
What I've done so far
I have written a series of formulas which extract parts of the string. For instance, for
12345(1234-COD-100 - 1234-COD-150)
I have extracted the following in individual cells
100
150
COD
1234-COD-100
1234-COD-150
I know I can create a series to manually populate each order ID within range, then perform a lookup but I have hundreds of values in List 2 so this isn't an option.
Another option is to take the value in List 2 (12345(1234-COD-100 - 1234-COD-150) and check if every number in the range 100-150 is found in List 1.
I would like to be able to use a formula (or even VBA) to achieve this, but haven't been able to get any further. Any help would be greatly appreciated!
Parsing text is always problematic. The following will return what you want:
=SUMPRODUCT((A2>=TRIM(LEFT(MID($C$2:$C$3,FIND("(",$C$2:$C$3)+1,LEN($C$2:$C$3)),FIND(" - ",MID($C$2:$C$3,FIND("(",$C$2:$C$3)+1,LEN($C$2:$C$3)))-1)))*(A2<=SUBSTITUTE(TRIM(MID($C$2:$C$3,FIND(" - ",$C$2:$C$3)+3,LEN($C$2:$C$3))),")","")))>0
But it depends exclusively on the pattern you are showing. Specifically that the range is always in () and the two ranges are separated by -

Using tbl.Lookup to match just part of a column value

This question relates to the Schematiq add-in for Microsoft Excel.
Using =tbl.Lookup(table, columnsToSearch, valuesToFind, resultColumn, [defaultValue]) the values in the valuesToFind column have a consistent 3 characters to the left and then varying characters after (e.g. 908-123456 or 908-321654 - i.e. 908 is always consistent)
How can I tell the function to lookup the value based on the first 3 characters only? The expected answer should be the sum of the results of the above, i.e. 500 + 300 = 800
tbl.Lookup() works by looking for an exact match - this helps ensure it's fast but in this case it means you need an extra step to calculate a column of lookup values, something like this:
A2: =tbl.CalculateColumn(A1, "code", "x => LEFT(x, 3)", "startOfCode")
This will give you a new column that you can use for the columnsToSearch argument, however tbl.Lookup() also looks for just one match - it doesn't know how to combine values together if there is more than one matching row in the table, so I think you also need one more step to group your table by the first 3 chars of the code, like this:
A3: =tbl.Group(A2, "startOfCode", "amount")
Because tbl.Group() adds values together by default, this will give you a table with a row for each distinct value of startOfCode and the subtotal of amount for each of those values. Finally, you can do the lookup exactly as you requested, which for your input table will return 800:
A4: =tbl.Lookup(A3, "startOfCode", "908", "amount")

Use of Offset, Vlookup, and Concatenate to return a list

On my "Pieces" sheet and table I have a bunch of IDs as follows:
Level ID Tenant Type Level SQM Tenant
1358001 Retail 1000 VACANT
1358002 Retail 1000 Schoc
1358003 Retail 1000 VACANT
1358004 Retail 1000 Wishbone
1358005 Retail 1000 Zebrano Ltd
1358006 Retail 1000 Cranfields
1358007 Retail 1000 Astoria
1358008 Retail 1000 Mall Drycleaners
1358009 Unaccounted Area 1000 Unaccounted Area
I have then got a "front" sheet where the data is sorted etc.
I want to be able to list on the front sheet multiple tenants for a single level. In the example above all the Tenants are on the same level: "00".
On the "front" sheet I then pull up the Level ID I'm looking at in cell I30 by using =CONCATENATE(F5,B15):F5= 1358 : B15= 00.
Cell I32 contains:
=COUNTIF(pieces[Level ID],(CONCATENATE(I30,"?"))) which returns 9.
Below this I want to make a 'dynamic' list of all the Tenants in level 00. I'm not completely sure how to do this (and I might be heading in the wrong direction) but I believe I have parts of the puzzle I just don't know how to piece it together.
I can return one Tenant with the following forumla:
=VLOOKUP(CONCATENATE(I30,"1"), pieces[[#All], [Level ID]:[Tenant]], 4, FALSE)
which returns the first tenant ("VACANT") correctly.
I was then thinking I could pull down a 'list' (just into the cells below) by using something like:
=OFFSET(VLOOKUP(CONCATENATE(I30,"1"),pieces[[#All],[Level ID]:[Tenant]],4,FALSE),0,0,I32)
which would use my COUNTIF statement to make a height of 9. However, this formula doesn't work and I can't manage to get it right, even after looking up a
Use the AGGREGATE¹ function to return the first, second, third, etc matching row numbers from the table to an INDEX function.
=IFERROR(INDEX(pieces[Tenant], AGGREGATE(15, 6, (ROW(pieces[Level ID])-ROW(pieces[#Headers]))/(LEFT(pieces[Level ID], LEN(I$30))=I$30), ROW(1:1))), "no more")
Fill down until you run out of matches. Change "no more" to a zero-length string (e.g. "") if you want the non-matching cells to appear blank.
   
¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

Visual Studio 2012 - Coded UI Test Builder: Assertion Formula?

While automating testing of a website shopping experience, I am attempting to verify that the subtotal, total, and tax are calculating properly. Since the price and/or tax will change in the future, I cannot simply assert the actual price value inside the control. Instead, I would need to build a calculation based upon the controls themselves and assert that quantity multiplied by individual price for each item added together equals the subtotal, and so on.
For example, say my controls for each are named such (control names are in asterisks):
Quantity = *UIItem2Cell*
(InnerText has a Value of 2)
Individual Price = *UIItem249Pane*
(DisplayText has a value of 2.49)
Individual Product Total (price x qty) = *UIItem498Pane*
(InnerText has a Value of 4.98)
Instead of validating the values are the actual numbers, can I write an assertion formula using the identifiers as variables?
Keep in mind, I am using the Coded UI Test Builder rather than writing the code outright.
If the Individual Product Total InnerText assertion comparator is AreEqual, can the Comparison Value be something like:
UIItem2Cell-InnerText * UIItem249Pane-DisplayText
A. Is this sort of formula possible?
B. If so, how do I write it?
(Please forgive me, as I am very green when it comes to this.)
You most certainly can. First off in your app itself it would be greatly useful to use IDs on your controls so you can match on just that criteria. that way your not using calculated values for search criteria.
Now as is in your question you will need to pull those values from the cells, calculate the Value and use it in your Search Criteria
// I'd recommend trimming text values:
// depending on how tables and such are rendered you'll have extra white-space characters
var firstValue = Double.Parse(UIItem2Cell.InnerText.Trim());
var secondValue = Double.Parse(UIItem249Pane.DisplayText.Trim());
var calculatedValue = string.Format("{0,N2}%", firstValue * secondValue);
// assuming your in a web app
var totalDiv = new HtmlDiv(currentHtmlDoc);
totalDiv.SearchProperties.Add(new PropertyExpression(HtmlDiv.PropertyNames.InnerText, calculatedValue, PropertyExpressionOperator.Contains));
Assert.IsTrue(totalDiv.TryFind());
SringAssert.Contains(totalDiv.InnerText,calculatedValue);

Resources