VBA // Check for duplicates and a second variable - duplicates

I'm working on a document that to help me handle tickets.
The document uses the columns A to P where the column B contains a ticket number (ex. AB1T77) and the column P contains the letter Y or N.
Since I'm quite new to programming, I have a hard time formulating the conditions correctly for an IF function.
I want the program to check if there are multiple rows with the same ticket number in column B and if there are, check the letter in column P.
If it finds two rows with the same number in B, it should delete the row with N in column P and change the background color of the row with the letter Y in column P.
If column P has an N in both rows, simply delete one of the rows.
If column P has an Y in both rows, change the background color of the rows.
Honestly, I haven't tried too much as I don't know how to make make the program test for duplicate text in the same column and check an other value in the same rows that the duplicate texts are in.

Related

How do I compare all rows in a columns incrementally but also group them at the same time in access?

This is the table that I would like to compare the values within the row groups incrementally however I would not like to compare rows amongst groups as it would come with negative values.
How do I achieve this on the same table? I am unfamiliar with subqueries
It sounds like what you need is a Calculated Field added as a third column to your table.
Instructions:
Select the drop down menu next to "Click to Add" to create a new column.
From the choices available select Caluculated Field and then Number.
The Expression Builder will open.
All you need to do from there is select the column you want to use as your primary number (in your case Number) from the Expression Categories, insert a minus sign, then select the number you want to subtract from the first number (in your case Group), again in the Expression Categories.
Name the column you created whatever you would like.

INNER JOIN in MySQL returns multiple entries of the same row

I am using MySQL through R. I am working with two tables within the same database and I noticed something strange that I can't explain. To be more specific, when I try to make a connection between the tables using a foreign key the result is not what it should be.
One table is called Genotype_microsatellites, the second table is called Records_morpho. They are connected through the foreign key sample_id.
If I only select records with certain characteristics from the Genotype_microsatellites table using the following command...
Gen_msat <- dbGetQuery(mydb, 'SELECT *
FROM Genotype_microsatellites
WHERE CIDK113a >= 0')
...the query returns 546 observations for 52 variables, exactly what I would expect. Now, I want to do a query that adds a little more info to my results, specifically by including data from the Records_morpho table. I, therefore, use the following code:
Gen_msat <- dbGetQuery(mydb, 'SELECT Genotype_microsatellites.*,
Records_morpho.net_mass_g,
Records_morpho.svl_mm
FROM Genotype_microsatellites
INNER JOIN Records_morpho ON Genotype_microsatellites.sample_id = Records_morpho.sample_id
WHERE CIDK113a >= 0')
The problem is that now the output has 890 observation and 54 variables!! Some sample_id values (i.e., the rows or individuals in the data frame ) are showing up multiple times, which shouldn't be the case. I have tried to fix this using SLECT DISTINCT, but the problem wouldn't go away.
Any help would be much appreciated.
Sounds like it is working as intended, that is how joins work. With A JOIN B ON A.x = B.y you get every row from A combined with every row from B that has a y matching the A row's x. If there are 3 rows in B that match one row in A, you will get three result rows for those. The A row's data will be repeated for each B row match.
To go a little further, if x is not unique and y is not unique. And you have two x with the same value, and three y with that value, they will produce six result rows.
As you mentioned DISTINCT does not make this problem go away because DISTINCT operates across the result row. It will only merge result rows if the values in all selected fields are the same on those result rows. Similarly, if you have a query on a single table that has duplicate rows, DISTINCT will merge those rows despite them being separate rows, as they do not have distinct sets of values.

SSRS adding a percentage column based on a specifc column category in a matrix/tablix

I have a matrix/tablix set up so there are 4 row groups going down the left-hand side and a column group called RegCompCategory:
When the report is run, the RegCompCategory column group produces 3 distinct columns based on the categories in the underlying data:
What I'd like to do is add another column before the RegCompCategory column group that will display a percentage of the "fully-marked" column against the "total" column:
I'm guessing I will need to write an expression for the fields highlighted above, but I'm not sure how to reference the RegCompCategory to identify specifically the "Fully-Marked" category of data.
Could someone give me a few pointers? Many thanks.
Try:
=Count(IIF(Fields!RegCompCategory.Value="Fully-Market",Fields!RegCompCategory.Value,Nothing))
/
Count(Fields!RegCompCategory.Value)
It will count the number of Fully-Market rows and divide by the total rows. I think that is what you are expecting.
Let me know if this helps you.

Summing columns in access reports based on other column's text

so I'm using Microsoft access reports and I need to be able to sum only the rows in a column that are designated in a separate column by text. So column A has either a Y or N for every row and I need to sum the numbers in column B that have a Y in column A.
I just don't know how to designate which numbers should be summed using the other column.
Thanks
IIF(A='Y',Sum([B]/[B Grand Total Sum]), 0)
Wouldn't you want to evaluate the A criteria before you SUM anything up?
Honestly in this case I don't think it matters, but in general you will want to do evaluations of criteria before you do any aggregations or you're inevitably decreasing your performance. Also, your results may be inaccurate if you do IIF evaluations of columns outside of the summation.
Sum(Iif([A]="Y",[B],0))/SUM([B]) Should do the trick.
This will add B if A = Y and 0 if A <> Y, then divide that SUM by The overall total of Column B.
You could also do this in the underlying query...

Storing ids in a MySQL-Link-Table

I have a table "link_tabl" in which I want to link three other tables by id. So in every row I have a triplets (id_1, id_2, id_3). I could create for every element of the triplet a column and everything would be fine.
But I want more: =)
I need to respect one more "dimension". There is an Algorthm who creates the triplets (the linkings between the tables). The algorithm sometimes outputs different linkings.
Example:
table_person represents a person.
table_task represents a task.
table_loc reüpresents a location.
So a triplet of ids (p, t, l) means: A certain person did something at some location.
The tuple (person, task) are not changed by the algorithm. They are given. The algorithm outputs for a tuple (p,t) a location l. But sometimes the algorithm determines different locations for such a tuple. I want to store in a table the last 10 triplets for every tuple (author, task).
What would be the best approach for that?
I thought of something like:
IF there is a tuple (p,t) ALREADY stored in link_table ADD the id of location into the next free slot (column) of the row.
If there are already 10 values (all columns are full) delete the first one, move every value from column i to column i-1 and store the new value in the last column.
ELSE add a new row.
But I don't know if this is a good approach and if it is, how to realise that...
Own partial solution
I figured out, that I could make two columns. Onw which stores the author id. One which stores the task id. And by
...
UNIQUE INDEX (auth_id, task_id)
...
I could index them. So now I just have to figure out how to move values from column i to i-1 elegantly. =)
Kind regards
Aufwind
I would store the output of the algorithm in rows, with a date indicator. The requirement to only consider the last 10 records sounds fairly arbitrary - and I wouldn't enshrine it in my column layout. It also makes some standard relational tools redundant - for instance, the query "how many locations exist for person x and location y" couldn't be answered by "count", but instead by looking at which column is null.
So, I'd recommend something like:
personID taskID locationID dateCreated
1 1 1 1 April 20:20:10
1 1 2 1 April 20:20:11
1 1 3 1 April 20:20:12
The "only 10" requirement could be enforced by using "top 10" in select queries; you could even embed that in a view if necessary.