Double (Nested) XLOOKUP with reverse search mode issue - google-sheets

I've created a profit/loss google sheet that allows me to price up a list of items for each project I'm working on (I've simplified it for the purpose of my issue I'm trying to solve). It works by referencing a master pricing sheet so that I can manage the current pricing from one location.
In the MasterCopy tab I'm importing the master pricing sheet for all my items. If you look at the first row, the first set of pricing for EUR, USD, AUD are my costs and the second set of those curriencies are my sell price.
https://docs.google.com/spreadsheets/d/1SE-FtDsJOblrlEpkxSwn3_L3MZ1VD6DNzTDlGTj0vCc/edit?usp=sharing
In the "Profit Loss" sheet I'm using a nested XLOOKUP formula. For columns F, G, and H the formula uses "1" for the search mode and for columns K, L, and M it is the same, but uses "-1" search mode so that it searches across the MasterCopy sheet headers in reverse.
XLOOKUP(F$2,MasterCopy!$1:$1,xlookup($A3,MasterCopy!$A:$A,MasterCopy!$1:$1000),,,1)
XLOOKUP(K$2,MasterCopy!$1:$1,xlookup($A3,MasterCopy!$A:$A,MasterCopy!$1:$1000),,,-1)
However, the issue I run into is that for some reason one of the column sets (EUR, USD, or AUD cost and sell) it will show the same pricing for the cost and sell columns for the corresponding currency. For example, cell L3 shows 1,025 USD, but the corresponding USD cost column also shows 1,025 USD, when it should actually be a value of 925 (which is correctly showing in the MasterCopy tab).
Any help would be really welcomed. I'm hoping it's a simple logic error, but just can't seem to get all the sets of pricing to show the correct values.
Edit 1
I reloaded the sheet and suddenly it's the AUD columns showing the same values. See image below
AUD columns showing same values

maybe just use the header 'AUD Sell' in Cell AR1 (MasterCopy)
AND
use this formula in Cell M3 (Profit Loss)
=XLOOKUP(M$2&" "&J$1,MasterCopy!$1:$1,xlookup($A3,MasterCopy!$A:$A,MasterCopy!$1:$1000),)
totally eliminating the search_mode which is causing this amiss.

Related

Dropdown lists & conditional formatting in Google Sheets

I am making my business spreadsheet and my business is selling in multiple countries. So, for example, I have a drop-down list (and when Country is chosen I want it to affect the rest of the spreadsheet). In that list, I have all the countries I sell to. What I want to do is for example when I select UK it will update all the prices and costs that are there to GBP AND also hide specific columns that are not necessary for the UK. The same goes for other countries if US is selected I want to see $ currency and hide the column of VAT tax since it doesn't apply to the US.
To summarize, when Country is selected from the dropdown I want it to show different values and hide 1-2 columns. Wondering if this is even possible in sheets. Hopefully, this makes a little bit of sense. Thanks for the help!
Yes It is possible, get only the columns you want from a range.
Dropdown from a list
Go to Data > Data validation Criteria: List from range and Enter a range or formula.
The Formula
Paste this formula next to srearch key range and below the column names you want to search, Take a look at this "freshly made" Example Sheet.
=ArrayFormula(IF($B$2:$B="",,VLOOKUP($B$2:$B,$G$3:$J$16,MATCH(C$1,$G$2:$J$2,0),1)))
Choose the country and all the data will be populated, replacate this formula column and expand the lookup range to get more info put in place.
we are using MATCH to return the matching index from the column above for example Currency C1 from the range G2:J2 which is 2 in this case MATCH function returns the matching value index "column" 2, to be used as an index for vlookup function.

Finding Conditional sum to determine the Units Sold Units Remaining in inventory sheet

I have a Google sheet Here is the spreadsheet which is used for determining the inventory at FIFO basis. I have different products that come into my stock and I sell them.
I bring in fruits and record entries in A to E columns using simple formulas. But the problem is here after the E columns from F to I. When the sale take place I increase the existing value in G1 and select E1, The formulas would dynamically display the selling price based on purchase price.
Say if I have sold 50 more apples then G1 becomes 550.
I am ok if the products are continuous like Green color (Apples), When the products are of different types they need to coined using SUMIFs or something else which I am not sure how to implement.
Please help to display based on yellow cells for entire table
Here is the
=MIN(C4,$G$1-SUM($F$3:F3))
Please see if this helps:
=IF(A4=$E$1,MIN(C4,$G$1-SUMIF($A$3:A3,$E$1,$F$3:F3)),0)
The formula is for F4 and needed to be copyed down.
It uses sumif for a product name + checks if current product is "apple" or one you've selected.

Automated Number Distribution in Spreadsheets

Beginner here!
Here's a spreadsheet trying to show what I mean.
Suppose I have data for metrics in comparison to my competitors.
The metrics are sorted highest to lowest and I want to turn the names of the other companies into "Company 1, Company 2, etc." along with the order of the metrics. Myself ("Me") remains unchanged.
With every data set the competitors could be different companies, and I could be ranked in a different position. The number of competitors could range from 1-20.
Is there a way to automate the green fields in the spreadsheet so that I can just paste the data and the competitor numbering stays constant no matter where I appear in the list?
Thank you!
Lighter Torches, I've added a sheet named "Erik" to your spreadsheet.
I've placed an array formula into two cells: G5 and J5. They are the same except for the relative cell references. Since it is an array formula, the single formula in G5 "runs" the entire data set generated in G5:H; likewise, the formula in J5 "runs" the entire data set generated in J5:K. Array formulas do not require dragging/copying to other cells.
Here is the G5 formula:
=ArrayFormula(QUERY(SPLIT({"Me"&"^"&IFERROR(VLOOKUP("Me",A5:B,2,FALSE),"NA");"Company "&ROW(INDIRECT("A1:A"&COUNTA(FILTER(A5:A,A5:A<>"",A5:A<>"Me"))))&"^"&SORT(FILTER(B5:B,A5:A<>"",A5:A<>"Me"),FILTER(B5:B,A5:A<>"",A5:A<>"Me"),FALSE)},"^"),"Select * Order By Col2 Desc"))
In your sample data, the companies are already ordered by rank, best to worst. But in the real world, it seems that may not always be the case. With that in mind, you'll notice that I moved your top performer to the bottom in the second data set. I've written the formulas to account for this (i.e., they will order the companies in the correct order whether they were originally in the correct order or not).
Also, if "Me" for some reason doesn't appear in a raw-data list at all, it still shows up, unranked, at the top of the generated list. Again, I tried to account for real-world what-ifs in the formula.
Finally, I added a sheet-wide custom Conditional Formatting rule that applies bold to any occurrence of the word "Me," since it seemed you were doing that manually. As such, you can type the sole word "Me" in any cell in the sheet, and it will automatically be formatted bold. You can see this rule by selecting Format > Conditional Formatting from the menu, then clicking on the rule you see in the window that appears.

Google Sheets: Dense Ranking from sorted values

I have a simple table with 3 columns:
[Name] [Score] [Rank]
For the 3rd column, I'm using the following formula to rank each row according to the score:
=RANK(C9,$C$9:$C$28,0)
The problem is that the formula isn't returning the values I'd expect. For example on the last row it returns 19 when it should be 5.
I found other formulas for ranking (RANK.EQ, etc.) but same issue happens.
Here is the Google Sheet to see it in context:
https://docs.google.com/spreadsheets/d/1P1m7UHPPIcQLQkzpnk-SI1y7-0mhKytCWDjA6FJzFrM/edit?usp=sharing
Any guidance appreciated
The results you want can be achieved with a simple MATCH formula:
=match(round(C9,0),NamedRange1,0)
Provided an array (named NamedRange1 for above) is created, say with:
=sort(unique(round(C9:C28,0)),1,0)
I think the result is as intended. Check this Ranking Wikipedia page (called 'standard competition ranking'). It says:
Standard competition ranking ("1224" ranking)
In competition ranking, items that compare equal receive the same
ranking number, and then a gap is left in the ranking numbers. The
number of ranking numbers that are left out in this gap is one less
than the number of items that compared equal. Equivalently, each
item's ranking number is 1 plus the number of items ranked above it.
This ranking strategy is frequently adopted for competitions, as it
means that if two (or more) competitors tie for a position in the
ranking, the position of all those ranked below them is unaffected
(i.e., a competitor only comes second if exactly one person scores
better than them, third if exactly two people score better than them,
fourth if exactly three people score better than them, etc.).
Thus if A ranks ahead of B and C (which compare equal) which are both
ranked ahead of D, then A gets ranking number 1 ("first"), B gets
ranking number 2 ("joint second"), C also gets ranking number 2
("joint second") and D gets ranking number 4 ("fourth").
What you want is 'dense ranking' and it can be achieved by pnuts's answer or something like this:
set G9 to 1
set G10 to =if(round(C10,0)<round(C9,0), G9+1, G9)
copy G10 and paste it into G11:G28
Sample sheet is here.
Thanks to #pnuts and #sangboklee for your solutions. I think I have a good solution now. It is pnuts's solution, just simplified:
=match(round($C9,0),sort(unique(round($C$9:$C$28,0)),1,false),0)
This essentially "embeds" the created array within a single formula, that can be applied to all rows. And as a bonus, the values don't even have to be sorted.
Please check for correctness folks, but I think this works. I've updated the linked Google Sheet from the original question description (it's "Solution 2b").

SUMIFS function across multiple sheets

For reference, please visit this Google Doc which is a simplified example of my problem, which is to determine total sales in Blue and Green markets each month.
Each month, I receive a new sales report from accounting for all of our markets and I add the sheet to the main workbook. My team is in charge of assigning "colors" to the markets and tracking this. As it's privileged information, we can't have accounting auto-tag these in the data they send over.
One solution would be, for each new monthly report that comes in, tag each city with the color. However, we have hundreds of markets and this isn't very practical to go through each time.
I assume that a SUMIFS function would work here, but am unsure how to set it up when there are values spread across multiple sheets.
You can use this function in B8 of February tab:
=SUM(IF(COUNTIFS($A$2:$A$5,Color!$A$2:$A$5,Color!$B$2:$B$5,'Sales February'!A8)>0,$B$2:$B$5,0))
COUNTIFS($A$2:$A$5,Color!$A$2:$A$5,Color!$B$2:$B$5,'Sales February'!A8)>0 gets an array of the countries that belong to the colour specified in A8 of the current tab (Would that be possible to put only Green and remove February Sales from that cell?).
If the country belongs to the particular colour, then return the array of corresponding values in column $B$2:$B$5.
Lastly, sum this array.
Note:
You need to array enter this formula in Excel (by holding Ctrl+Shift then hit Enter after typing in the formula).
In Google Spreadsheets, you array enter a formula by wrapping the formula around =ArrayFormula(), meaning you use:
=ArrayFormula(SUM(IF(COUNTIFS($A$2:$A$5,Color!$A$2:$A$5,Color!$B$2:$B$5,'Sales February'!A8)>0,$B$2:$B$5,0)))
In Excel you can use this "array formula"
=SUM(SUMIF(A$2:A$5,IF(Color!B$2:B$5=A8,Color!A$2:A$5),B$2:B$5))
confirmed with CTRL+SHIFT+ENTER
The same formula works in google docs if wrapped in arrayformula, i.e.
=arrayformula(SUM(SUMIF(A$2:A$5,IF(Color!B$2:B$5=A8,Color!A$2:A$5),B$2:B$5)))
or you can use FILTER as user3465711 suggests, i.e.
=SUM(filter(B$2:B$5,isnumber(match(A$2:A$5,IF(Color!B$2:B$5=A8,Color!A$2:A$5),0))))

Resources