Ifelse statement based on count in a Pivot table - calculation

Currently looking for a way to create a calculation in Pivot.
Where if the count of Table1 is equal to the count of Table2, then return ‘blank’
if not, then return the current value.
Output
Desired Output
Only 108 would show in ''Table1" the rest are ‘empty’
Any help would be appreciated.

Related

Rank column with arrayformula and cull duplicates based on another column

I'm struggling with a Google Sheets arrayformula. I want to make an arrayformula to show rank position of Column B values (TOT). With my formula I just achieve a copy of the first position. I don't want duplicate values in the rank, so if there is two equal values the Column A sets the priority.
={"POS";ARRAYFORMULA(IF($B2$B:$B<>"";RANK.EQ(B3;B3:B42;0)))}
Test Document:
https://docs.google.com/spreadsheets/d/1qzs1nvpzG0VgygxbXF9bKxvGaAq-H29oI1aquupYNFc/edit?usp=sharing
If you put this in cell C2, it will rank them as you're trying to do. If you wanted to match the other direction (lowest to highest), then swith the sort parameter from false to true.
=Filter(match(B2:B+(A2:A/1000),
Sort(Filter(B2:B+A2:A/1000,B2:B<>""),1,false),0),A2:A<>"")
You also appear to have duplicates including in column A (example see rows 4,25,35). If you wanted to exclude the duplicates (effectively reducing the number of ranked values), This can be done using the unique function which would create a 17 in each row.
=Filter(match(B2:B+(A2:A/1000),
Unique(Sort(Filter(B2:B+A2:A/1000,B2:B<>""),1,false),0)),A2:A<>"")

Counting the number of times a value appears more than once in a column AND where another conditon is met

Any help in figuring this out would be appreciated. I would like a forumla to calculate the number of times a code number appears more than once AND where type is A.
A sample set of data looks like the following:
In this case the forumla should return 1 as there is one case of a repeated code number (1) where type is (A) - first row and last row in this case.
Would the forumla be any different if I also had a third column and wanted that to be a certain value as well? Again with the test data below I would want this to return 1 in the case that I wanted to measure the number of times any code number appeared more than once where type=A and subtype=C:
.
Ihave started with the following which identifies the number of unique combinations in columns A and B, but I can't seem to add any way to only return where a particular combination appears more than once:
=COUNTUNIQUE(IFERROR(FILTER(A2:A,B2:B="A"),""))
I have tried the following but it doesn't return correctly:
=COUNTUNIQUE(IFERROR(FILTER(A2:A,B2:B="A",COUNTIF(A2:A,A2:A)>1)))
Been trying to figure this one out for a while with no success.
Thank you
You can try this (TABLE = the range corresponding to your dataset, including the header row):
=query(query(transpose(query(transpose(TABLE),,9^9)),"select Col1,count(Col1) where Col1 contains 'A' group by Col1",1),"select Col2-1 where Col2>1 label Col2-1 ''")
What we are doing is to concatenate the Code number & type columns into one using the TRANSPOSE/QUERY/TRANSPOSE...9^9 hack, querying it again to make a temporary table of each group against its count for those groups which meet the criteria, then finally subtracting one from each group count and only returning an answer if there were groups with count>1 to begin with. You will get multiple results if multiple groups satisfy the count>1 criteria.
To add the subtype column to the formula as per the second question, change TABLE to suit, then change the inner QUERY to:
"select Col1,count(Col1) where Col1 contains 'A' and Col1 contains 'c' group by Col1"
Note that the if your 'real' type & subtype categories share characters then the where/contains approach in the QUERY will fail and a different approach will be needed.
Assume that you place you data at A1:B10, what this function do is:
FILTER B1:B10 by type, which is "A" in this example, and return an array which is filtered A1:B10.
Use INDEX to extract only the 1st column, which is the code column of the filtered array, and name it 'DATA' with LAMBDA function.
Use BYROW to iterate 'DATA', and check each code with COUNTIF, if it counts more than one of this code in the filter result, return that code, else return "".
Use UNIQUE to get rid of duplicate results. (since we are looking for code which have more than 1 repeats, so the return array will sure have duplicates.)
Use query to get rid of the extry empty rows.
=QUERY(UNIQUE(
LAMBDA(DATA,
BYROW(DATA,LAMBDA(ROW,
IF(COUNTIF(DATA,ROW)>1,ROW,"")
))
)(INDEX(FILTER(A1:B10,B1:B10="A"),,1))
),"WHERE Col1 IS NOT NULL")
Just noticed that the INDEX function is not necessary, FLITER can directly returns A1:A10 according the compare results of B1:B10.
=QUERY(UNIQUE(
LAMBDA(DATA,
BYROW(DATA,LAMBDA(ROW,
IF(COUNTIF(DATA,ROW)>1,ROW,"")
))
)(FILTER(A1:A10,B1:B10="A"))
),"WHERE Col1 IS NOT NULL")

Index formula on multiple columns

Is it possible to use this index formula on multiple columns?
=index(if(Sheet1!B5:B<>"",,Sheet1!A5:A))
[Sample Table]
For the table above, what if we want to add Column C? (If column B and C have data on Sheet 1 - remove them, and if 1 is missing in either column(B or C), it will appear.
The desired results shown in the screenshot suggest that you want the matching data without inserting blank rows in between. To get that, use filter(), like this:
=filter(Sheet1!A5:A, isblank(Sheet1!B5:B)
To add another criterion, and combine the criteria with OR, use the + operator, like this:
=filter(Sheet1!A5:A, isblank(Sheet1!B5:B) + isblank(Sheet1!C5:C))
To get an AND condition, simply add criteria as their own parameters, or use the * operator. See Boolean arithmetic.
FILTER() with MMULT() may give you desired result.
=FILTER(Sheet1!A4:A,MMULT(INDEX(--(Sheet1!B4:C="x")),{1;1})<2)
Here MMULT(INDEX(--(Sheet1!B4:C="x")),{1;1}) will create a vertical array having count how many x do you have in each row. If you have x in both column of each row then MMULT() will return result 2. If you have one x then will return 1 and if there is no x then 0. Then we will filter that vertical array having values less than 2.
MMULT() reference.

How to use ROUNDDOWN() in pivot table's calculated field and return correct grand totals?

In this post, I got to know that using ROUNDDOWN() in a pivot table's calculated field is what causes the grand total to display an incorrect value. So I want to ask, how to use ROUNDDOWN() in a pivot table's calculated field and still return correct grand totals? Specifically, how to use the one that rounds down to the nearest thousand (, -3)? How it is now (showing 0 when it is not near a thousand) is perfect, the only issue is how to show the grand total correctly with those zeroes instead of irrelevant non-thousand values
With ROUNDDOWN() (=ROUNDDOWN((Cheating*25)-('Not Cheating'*100), -3)):
Without ROUNDDOWN() (=(Cheating*25)-('Not Cheating'*100)):
I already have this formula outside of the pivot table as a temporary solution:
=ARRAYFORMULA(IF(J2:J <> "", ROUNDDOWN((K2:K*25)-(L2:L*100), -3), ""))
Here is the spreadsheet with the source data.
Short Answer: Not Possible
How to use ROUNDDOWN() in pivot table's calculated field and return correct grand totals?
I don't think this is possible because what the pivot table is doing in the grand total row, is applying the same calculated formula to the individual grand totals in columns K and L. It does not actually calculate the total of your calculated field column.
Workaround
It's possible to get the pivot table to show the values you want, by adding a helper column to the spreadsheet:
Insert a column I after column H of your spreadsheet. In I1 put the following formula:
I1:
={"Weight";ARRAYFORMULA(ROUNDDOWN(COUNTIFS(E$2:E,E2:E,G$2:G,1)*25-COUNTIFS(E$2:E,E2:E,H$2:H,1)*100,-3)/COUNTIFS(E$2:E,E2:E,G$2:G+H$2:H>0,TRUE))}
Then, add that column as a value in your pivot table, using SUM as the summary statistic.
Formula explanation
This part of the formula
ROUNDDOWN(COUNTIFS(E$2:E,E2:E,G$2:G,1)*25-COUNTIFS(E$2:E,E2:E,H$2:H,1)*100,-3)
calculates the rounded aggregate sum for each identifier, and places it in every row where that identifier is found.
Then /COUNTIFS(E$2:E,E2:E,G$2:G+H$2:H>0,TRUE) divides (averages) that value among all of the rows for that identifier, which allows the SUM in the pivot table to aggregate them properly.
The main idea is that we are calculating the ROUNDDOWN function outside the pivot table, so that the pivot table only views the already-rounded values.
I'm not sure this will give you correct totals for individual month-years, but you should be able to adapt it to do so with an additional condition on the COUNTIFS.
In a normal use case this rounddown only values with max length in the provided range.
=ArrayFormula(IF(ROW(A2:A)<=ROW(A2:A),
IF(LEN((A2:A*25)-(B2:B*100))=MAX(LEN((A2:A*25)-(B2:B*100))),ROUNDDOWN((A2:A*25)-(B2:B*100),-3),(A2:A*25)-(B2:B*100))))
In the pivot table, calculated field put
=ArrayFormula(IF(LEN((Cheating*25)-('Not Cheating'*100))>4,ROUNDDOWN((Cheating*25)-('Not Cheating'*100),-3),(Cheating*25)-('Not Cheating'*100)))
Note:
Keep in mind ...>4... in the formula decides when to rounddoun if the LEN length of the value is greater than >4 then rounddoun.
I hope this is helpful.

Multiple queries by date in the same row in google sheets

I need to sum the daily sales of each product ASIN. Sounds easy but I can`t do it.
On the left, you can see the data. At the right, the empty table that I need to create.
use:
=QUERY(K2:M; "select K,sum(M) where M is not null group by K pivot L")
Use an IF statement on the columns that you want summed.
For your example, it would be something like this:
in Cell P2
=IF($L2 = P$1, $M2, 0)
This translates to
If ((the text in column L row 2 = the text in p1), take the units from column m row 2, else take 0)
The $ are there to indicate you always want that column/row. So we always want to evaluate column L at the start and Row 1 in the comparison.
Then at the last row of the sheet you have a SUM function for the column
=SUM(P2:P100)
or whatever the end is
Working example here: https://docs.google.com/spreadsheets/d/1zhQMV6o1tF2P_kWbXDPdnVKzYnd-Dsvg2h7YiHWSaNI/edit?usp=sharing

Resources