I have two tables and want to take a row of one and a column of the other as two arrays, then multiply first with first, second with second... and sum up all those products.
This is what I got:
=SUMPRODUCT(OFFSET(Rezepte; MATCH([#Cocktail]; Rezepte[Cocktail]); 1; 1; 36); OFFSET(Zutaten; 0; 1; 36; 1))
As you can see I try to take arrays from my tables using OFFSET and calculate my answer using SUMPRODUCT
It returns "A value in this formula is the wrong data type", however when I put the either one of the inner OFFSET functions twice instead of the other one, it works just as intended. So there seems to be some incompatibility there.
The first table contains recipes for cocktails, each cocktail has a row of values for the measures of all ingredients. The second table lists all ingredients and what their price per liter is (currently dummy values). I want to multiply the measures with the prices and add the values to calculate the price for each cocktail. I know, it's kind of an odd use case :)
And here is what the tables look like:
Table one, of which I want to take one row
Table two, of which I want to take one column
Table three, in which I want the answer to be displayed
When using SUMPRODUCT() on a row and column, I use TRANSPOSE():
=SUMPRODUCT(A1:C1,TRANSPOSE(E3:E5))
Related
Here is an example of the data I'm trying to organize:
I'm looking for a way to automatically see the top 3 categories (column) for each Name# (row). The size of the category is determined by the number below the category.
Ideally, I'd also like to see a percentage breakdown (from the total) for each category. For example, in row "Name3" 2 categories make up a significantly larger portion of the total values. However, without this percentage breakdown, the 3 top values would seem to be comparable, when they are in fact, not.
Interested to see how this would all work with duplicate numbers, too.
I've tried Excel's rank function, but this doesn't tell me the categories that have the 3 largest sizes, just the 3 highest values.
With Office 365:
=FILTER(SORTBY($B$1:$H$1,B2:H2,-1),SORT(B2:H2,1,-1,TRUE)>=LARGE(B2:H2,3))
And copy down.
If there are ties it will expand the results to include it. It finds the third highest value and returns everything that is equal to or greater than it.
This approach spills all the results at once (array version). In cell J2, you can put the following formula:
=LET(D, A1:H5, A, TAKE(D,,1), DROP(REDUCE("", DROP(A,1), LAMBDA(ac,aa,
VSTACK(ac, TAKE(SORT(DROP(FILTER(D, (A=aa) + (A="")),,1),2,-1,1),1,3)))),1))
It assumes as per input data the cell A1 is empty (if not it can be adjusted accordingly). Here is the output:
An alternative that doesn't require previous assumption (but it is not really a hard one) is the following:
=LET(names, A2:A5, Data, B2:H5, colors, B1:H1, DROP(REDUCE("", names,
LAMBDA(ac,n, VSTACK(ac, TAKE(SORT(VSTACK(colors, INDEX(Data, XMATCH(n,names),0))
,2,-1,TRUE),1,3)))),1))
The non-array version can be obtained from previous approach, and expand it down:
=TAKE(SORT(VSTACK($B$1:$H$1,INDEX($B$2:$H$5, XMATCH(A2,$A$2:$A$5),0)),2,-1,TRUE),1,3)
Explanation
To spill the entire solution it uses DROP/REDUCE/VSTACK pattern. Check my answer to the following question: how to transform a table in Excel from vertical to horizontal but with different length.
For the first formula we filter for a given element of A name (aa) via FILTER the input data (D) to select rows where the name is empty (to consider the header) OR (plus (+) condition) the name is equal to aa. We remove via DROP the first column of the filter result (names column). Next we SORT by the second row (the first rows are the colors) in descending order (-1) by column (last input parameter of SORT we can use TRUE or 1). Finally, we use TAKE to take the first three columns and the first row.
For the second approach, we select the values for a given row (names equals n) and use INDEX to select the entire row (column index 0), then we form an array via VSTACK to add as first row the colors and use the similar logic as in previous approach for sorting and select the corresponding rows and column (colors).
Notes:
If you don't have VSTACK function available, then you can replace it as follow: CHOOSE({1;2}, arr1,arr2) and substitute arr1, arr2, wit the corresponding arrays.
In the second formula instead of INDEX/XMATCH you can use: DROP(FILTER(Data, names=n),,1), it is a matter of personal preference.
I have a huge amount of data to process in which 4 points with a related prefix needs to be subtracted from each other.
Data consists of ID and x value
Example
ID = 290.12, 290.03, 290.06, 290.09, 300.12, 300.03, 300.06, 300.09, 301.12, 301.03, 301.06, 301.09
(let's call prefix a "ring number" and suffix time on the clock)
X value = any numerical value for each ID assigned
What I'm hoping to do is to search for the first number before the dot i.e. 300 and then subtract the value of 300.06-300.12 in one cell and in another cell 300.03-300.09.
(The subtraction is just an example, how I need to manipulate with the numbers is slightly more complicated, but I got this one under control)
This is my actual Data and what I need to produce is to the right of the raw data. At the moment, I'm doing it manually for each set of "rings"
Anyone knows how to approach this? I'm thinking vlookup, but I'm not very proficient in excel.
New Excel
I tried vlookup, but I don't know how to construct the formula and I run out of ideas.
Edit:
I found out that REDUCE is no requirement in this case, so it can be shortened to:
=SQRT(SUM(((INDEX(B:D,XMATCH(I3+0.09,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(I3+0.03,A:A),SEQUENCE(1,3)))^2)))
You could change +0.09 and +0.03 to your needs and may reference them using LET() for easy maintaining:
=LET(id,I3,
_id1,0.09,
_id2,0.03,
SQRT(SUM(((INDEX(B:D,XMATCH(id+_id1,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(id+_id2,A:A),SEQUENCE(1,3)))^2))))
Previous answer:
=LET(
id,I3,
_id1,0.09,
_id2,0.03,
SQRT(
REDUCE(0, SEQUENCE(1,3),
LAMBDA(x, y,
x+((INDEX(B:D,XMATCH(id+_id1,A:A),y)
-INDEX(B:D,XMATCH(id+_id2,A:A),y))
^2)))))
This formula looks for the matching value of the id value I3 + _id1 minus the matching value of id value + _id2 for columns B to D and adds the ^2 results per column. Then it calculates it's square root.
You can change _id1 and _id2 to your needs.
To calculate the Delta (as shown) at once you could use:
=LET(id,I3,
_id1,0.09,
_id2,0.03,
_id3,0.12,
_id4,0.06,
x,SQRT(SUM((INDEX(B:D,XMATCH(id+_id1,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(id+_id2,A:A),SEQUENCE(1,3)))^2)),
y,SQRT(SUM((INDEX(B:D,XMATCH(id+_id3,A:A),SEQUENCE(1,3))-INDEX(B:D,XMATCH(id+_id4,A:A),SEQUENCE(1,3)))^2)),
(x-y)*1000)
You can have a column of unique values of the integers and a new column where you reference these values as id and drag down the formula to get your row by row result
In another column you can refer to these columns and sort per the second column using SORTBY()
If we have a table of sports teams, that have all played against each other and two teams are on top equal with x points, the winner would be crowned with the highest average goal differential.
But how would you do that with a formula in Excel?
This is the formula I am using to find the team with the highest points total:
=INDEX($C$8:$C$11,MATCH(MAX($K$8:$K$11),$K$8:$K$11,0))
This formula would give me the result of Ecuador being highest (first result of max value).
But in reality Qatar should be on top based on same points total AND average goal difference being higher.
Any solutions?
I assume you want to sort in descending order first by column P, then by column GD. If that is not the case, you can adjust it accordingly. In cell A8 you can put the following formula:
=TAKE(SORT(A3:I6, {9,8}, -1),2,1)
Here is the output:
You can also select the columns of your interest first via CHOOSECOLS then SORT:
=TAKE(SORT(CHOOSECOLS(A3:I6,1,8,9), {3,2}, -1),2,1)
If you want to include the row title, then:
=HSTACK({"First Place";"Second Place"},TAKE(SORT(A3:I6, {9,8}, -1),2,1))
Note: MATCH/XMATCH is not appropriate in this context, because what you really need is to sort the result, not finding values that match certain conditions. You can do it, but at the end you will end up implementing a sort manually and Excel has a built-in function for that. The resulting formula will unnecessary more verbose.
With SORT function you can use more than one criteria indicating in an array the columns to consider as first and second criteria, etc.. For your example it would be: {9,8} indicating as first sorting criteria column 9 and then column 8, so if column P have the same value, then it sorts by GD. The third input argument is to specify ascending (1, default)/descending order(-1). If you want to have a different sorting criteria for each column, then instead of -1, you can use it {-1,1} which means sort in descending order the column 9 and in ascending order the column 8. For your case you can use also: {-1,-1}, but using -1 produce the same result.
I am doing quotations in Excel for my company and I am trying to find a way to do 2 things:
aggregate several quantities of the same product based on its reference number
return several values for the same references (i.e. different prices)
I was thinking about using VLOOKUP but I cannot find a way to make it sum or return multiple values.
Table outline in the picture attached here, the wanted result would be:
- for the 1st function: sum up the table into 3 lines with aggregated quantities for products X Y Z
- for the 2nd function: sum up the table into 4 lines with the prices for products X Y Z (X having 2 different prices in the sample data, but I would need the function to be able to return as many lines as there are different prices for the same product)
Thank you very much for you help!
Kind regards,
Antoine
Edit: to get a better idea of what I try to achieve, here is another picture:
2nd pic with annotations
Quantities of the same product have to be aggregated, except if the unit price is different.
Could price difference be based on a subreference to be added to the first table? That would need the vlookup to match 2 values to return a result, is that feasible?
Noting that I do not have control over the source data for unit price, meaning that reference and subreference would have to be in different columns rather than concatenated.
The goal is to produce a recap table rather than filter out single values as suggested in the answer.
So, try this:
Cell B10 is the product you want to look at then G2 is the test if the product on that row matches. Finally, the sumproduct calculates the total, but you can change which column it looks at, I just chose the total column.
Now showing use of data validation from a list:
I have two columns in a pivot table. Count of Work orders, and Sum of the Cost.
I want to insert a calculated field that simply divides the sum of cost by count of work orders to get an average per work order.
When I put I insert a calculated field with the following formula, it yields the total cost, not the average. You'll see the fields are subtotal (cost) and WO#(work order)
And here is what the output looks like in my pivot table.
When you add a calculated field in a pivot table, you need to only add the reference, not a calculation inside of it, so you don't need to add Sum or Count in your definition. However, Excel works calculated fields in a very infuriating manner - first it adds your values and then performs the calculation - if, for example, I have a calculated field that's simply field3=field2/field1, when I want to display the SUM of these values, instead of sum(field3), it does sum(field2)/sum(field1)
I would recommend doing this calculation outside of the pivot.
For example, see my results when I have the following table as input for a pivot
I had the same issue and found the answer I needed. Like the OP, I want to calculate an average -- SUM(field 1) divided by COUNT(field 2) -- but the problem with this is that there are two functions in the same formula (SUM divided by COUNT). As we have seen, using multiple functions in the same calculation produces unintended results.
The key that worked for me was to create a new field (field 3) in the raw data with a formula that assigns a 1 to items I want to count and a 0 to items I don not want to count, so the count of this column is just the sum. In this way, I convert COUNT(field 2) in the denominator to SUM(field 3). So, the result I need is now SUM divided by SUM, same function on top and bottom, which Excel can handle. And luckily for me in this situation, Excel's "infuriating manner" of calculating is exactly what I want.
As Fernando stated, the calculated field should just refer to the field itself; it shouldn't use SUM or COUNT or anything else. The function you want will be applied when you add the field to the pivot table and you choose the function you want.
I set my calculated function to be [field 1 / field 3], with an IF statement to avoid division by 0, and I used the SUM function when I put the calculated field in the pivot table. The end result is SUM(field 1) / SUM(field 3), which equals SUM(field 1) / COUNT(field 2)
Summary:
Restate your formula so that the same function is used on all fields; for example, find a way to restate an average (SUM/COUNT) to be SUM/SUM or COUNT/COUNT, etc.
Add fields to the raw data that will aid in the restated formula; for example, if your restated formula uses a SUM instead of a COUNT, create a new field in the raw data that assigns 1's and 0's so that the sum of this new field is equal to the count of the other field.
Create the calculated pivot field that uses the fields corresponding to the restated formula, including the new field you just created; do not use SUM or COUNT at this point.
Add your calculated field to the data area of the pivot table and choose the function you want; this function will be applied to each field that is referenced in the formula of the calculated field.