Matches where an occurrence of X is Y but the corresponding Z is missing - google-apps-script

I am trying to create a formula (or script) that is able to find all the occurrences of a plate number and return 1 if 'BOUGHT' has been found, but 'SOLD' is missing for that plate number.
The dataset that looks like this:
Column A is a list of plate numbers and B is the type ('BOUGHT' or 'SOLD').
I need to find the plate numbers for which there is a 'BOUGHT' but no 'SOLD'.
I tried using the formula below (and many others):
=ARRAYFORMULA(IFERROR(IF(
((VLOOKUP(A2:A,A:B,2,0)="VÉTEL")
+
(VLOOKUP(A2:A,A:B,2,0)="ELADÁS"))<>2
,1,0)))
Since nothing seems to be working, any help would be highly appreciated.
I created a sample worksheet, which can be found here.

Try below formula-
=ArrayFormula(IF(COUNTIFS(A2:A,A2:A,B2:B,"BOUGHT")>0,IF(COUNTIFS(A2:A,A2:A,B2:B,"BOUGHT")*(COUNTIFS(A2:A,A2:A,B2:B,"SOLD"))=0,1,""),""))
See your sheet.

Related

Countif Formula to exclude Duplicates

I sought help regarding this once, but I failed to outline my problem.
This time I am happy to share the sheet with dummy data in hope it explains my problem a bit better: Link to the sheet
My issue is the following:
In column E I am counting the number of opportunities for a rep (listed in column A). The data I am considering is in a separate sheet named "Pipeline".
I do this with the countif formula and I use additional criteria to filter on date as well. My dates for february are in B4 and G4, because I only want to see opportunities in February.
My formula looks like this:
=countIFS(Pipeline!$A:$A,$A7,Pipeline!$F:$F,">="&$B$4,Pipeline!$F:$F,"<="&$G$4)
This works perfectly fine. However, sometimes I have two opportunities in my pipeline sheet with the same name (these are split opportunities). If an opportunity has the same name it should be counted only once. I can't seem to find an easy way to update my countif formula.
In the dummy sheet I shared above, you can see that Peter has two "New - CC Tech" opportunities. I want this to count as one opportunity. Everything I googled so far suggests using rather complex formulas, which is not so easy as I have multiple criteria in the formula that I need to filter my results (such as name of the rep and dates). Please feel free to suggest a solution within the sheet above and play around with it.
I really appreciate the help!
Try this ('unique' based on A,B and F)
=query(unique({Pipeline!A:B,Pipeline!F:F}),"select count(Col1) where Col1='"&A7&"' and Col3>=DATE'"&TEXT($B$4,"yyyy-MM-dd")&"' and Col3<=DATE'"&TEXT($G$4,"yyyy-MM-dd")&"' label count(Col1) '' ")
or, if you consider that the date could be different between two lines ('unique' based only on A and B, the date could be different but within the limits)
=query(unique({Pipeline!A$2:B,arrayformula((Pipeline!F$2:F>=$B$4)*(Pipeline!F$2:F<=$G$4))}),"select count(Col1) where Col1='"&A7&"' and Col3>0 label count(Col1) '' ")
In this second formula, we construct a matrix with A, B and 0/1 (which is the result of the question: is F within limits), then we apply unique and we query when Col3 is equal to 1 and Col1 the name we are looking for

Removing duplicate/opposite entries in Google Sheets

I have a sheet containing the following data:
URL A, URL B, similar score in percent.
If URL A is 98% similar to URL B, it means that URL B is 98% similar to URL A, and listed as well.
I want to find and eliminate these duplicates/reversed entries. For now, I have tried having two extra columns concatenating URL A+URL B in one, and URL B+URL A in one. This way I have unique identifiers.
After this I'm kinda stuck, because I'm dealing with a lot of variables, as data is in two different rows, and two different columns. I might be looking into a script, taking the A+B value, iterating through the B+A value until it finds a match, and somehow marks this (or simply just deletes it), since my knowledge of formulas for highlighting these duplicates are falling short.
This sheet shows the concept - the first 100 rows (it's about 11K in total): https://docs.google.com/spreadsheets/d/1YKsguAn1lYjV4FlP_6_TlKGvFcpFAEzn7bpAyOEmozQ/edit?usp=sharing
Any suggestions for what I should look into?
Try the filter(match()) pattern to find duplicate values, like this:
=unique(
flatten(
filter(
A2:B,
match(A2:A & B2:B, B2:B & A2:A, 0),
C2:C >= 90
)
)
)
I ended up with a solution where I sorted by URL A and implemented this formula:
=IF(A2<B2,A2&B2,B2&A2)
This way I had the concatenation the same way for the real one and the opposite. I didn't know you could use "<" on strings.
After this, I could delete duplicated values in the column with the formula above.

Google Sheet Formula to sum based on conditions

The following formula is designed to sum column C when column B contains a specific string:
=sum(query(A:C, " select C where B contains '2018-09-10' "))
https://i.stack.imgur.com/zjiJS.png
It looks straightforward but it doesn't work in the Sheet:
https://docs.google.com/spreadsheets/d/1qpQiwxHOUzoMTqHnn-m-nsnvl63YJkVIGgqpXzOZgzU/edit?usp=sharing
Am I missing something? Others have posted similar threads but this problem looks specific to this particular use case.
months late but saw this searching for a similar problem, the problem comes from that what sheets stores with a date is different than what you see if you change it to:
=sum(query(A:C, " select C where B = date '2018-09-10' "))
it should work, alternatively, you can just select the column and choose Format -> Number -> Plain Text and your formula will work but then you won't be able to treat it as a date elsewhere in the sheet
By Cell Reference:
=sum(query(A:C, " select C where B = date '"&TEXT(B3,"yyyy-mm-dd")&"'",1))

Searching ALL ROWS in a Group using IIF Expression

I am working on a report that displays patient names (as groups with drilldowns) and several fields related to their visits. I have created a column in the report to display whether or not a specific value appears in the 'LocationID' column. The expression I used is
=IIF(Fields!LocationID.Value="WELL","Y","N")
I thought this was working great, it displays Y or N next to each name to let me know if 'WELL' was in their 'LocationID'. I checked several to ensure that this was going to work and discovered that there was a LocationID code of 'WHS' and since I have the rows ordered by Name and LocationID if there was a WHS visit it shows up at the top of the group and my expression is only seeing this top item. How can this expression be written differently so that it searches the entire result of each group? Depending on the date range a patient may have one visit or they may have ten. I need to check all visits that are returned. Perhaps there is a better method. Thanks in advance.
I agree with jimmy8ball that the easiest way to solve most issues like this is to push some logic back into the SQL layer.
However, if you really want to do this via SSRS functionality, then you could implement a substring search against a lookupset. Assuming you have a patient id in your dataset that is unique for each patient (I hope your group isn't on the name) then...
=Iif(InStr(Join(Lookupset(Fields!patientid.Value, Fields!patientid.Value, Fields!LocationsID.Value, "dataset"), ","), "WELL") > 0, "Y", "N")
Which says, "Search through the dataset for all rows related to my patientid, join every location into a comma deliminated string, search the string for the text "WELL" and return "Y" if it's found.
Obviously if you have locations in your dataset like "WELLY", these will become false positives and you'll have to implement some more nested logic. Try appending a value (perhaps !) to the lookupset return field so that you can search for "WELL!" or some other terminator character.

Problems with my Dlookup and Dmax

I'm trying to solve a problem in Access-2010. A Student number consists of 1314 followed by a 4 digit number.
The 4 digit number is sequential i.e. each one is 1 higher than the last. So, if the last Student number in use was 13140925 then the next should be 13140926.
The formula at present looks like this:
=1314&DMax(“Right(StudentNumber,4)”,“TBLStudent”)+1
However, this generates an error. I've also tried this:
=DLookUp(“Left(StudentNumber,4)”,“TBLStudent”&DMAX(Right(“StudentNumber,4)”,“TBLStudent”)+1)
Which I prefer as the 1st 4 digits can be anything and not just 1314. Anyhow, can someone please help me to identify the mistakes?
This should do:
=Left(DLookUp("StudentNumber","TBLStudent"), 4) & Right(Val(DMax("StudentNumber","TBLStudent")) + 1, 4)