Not sure I can help further because I can't see where you answered questions from post 30, the most important maybe being "
So does the posted db represent the correct or incorrect results?" I shouldn't have to tweak your data or db objects without knowing what to look for, especially after asking, but I did anyway. With this
Code:
TRANSFORM Max(TBL_demonstration.result) AS MaxOfExpr4
SELECT TBL_demonstration.comment1, TBL_demonstration.Comment2, TBL_demonstration.Samp_ID
FROM TBL_demonstration
GROUP BY TBL_demonstration.comment1, TBL_demonstration.Comment2, TBL_demonstration.Samp_ID
ORDER BY TBL_demonstration.Samp_ID
PIVOT TBL_demonstration.target;
I get what
looks like a satisfactory result, but is that what you did and is that what it should look like??
I find that it's enough to add a period or semicolon at the end of one sample1 comment to produce an extra record for sample1, although I started by adding extra text in comment 1 field. Looking further, I found your original data included a period at the end of a comment. When I removed it, I got a different result again.
So here's what I don't like about your db:
- Your table has no PK and I believe you'd need one in the query to produce better results.
- the table field you want to use as the query column isn't indexed/no dupes but looks like it should be
Other considerations which may be of a lesser but contributing issue:
Not understanding the business as well as you do, also ...
- try moving comments into their own table
- general design principles dictate that a form/report or table shouldn't have to be modified to accommodate a new member for the attributes of an entity (e.g. in your case, if a new element needed to be tested for, you'd have to modify your table). This suggests that something(s) needs to go into its (their) own table(s). In support of this is the fact that there are many records for the same sample with the only variation being the target and result, so the targets probably should be on their own as well as the comments. Thus it isn't the table that would produce many records for a test; rather it would be a query that you'd use as the basis for a ct query. This may even eliminate the problem you have since you wouldn't be basing your ct query on a table that doesn't appear to be correctly designed. Who knows, this might even eliminate the affects of periods/semicolons, etc. when a select query is the basis of your ct query.
Last but not least, if you don't intend to follow that advice (or can't) or even if you do and execute everything properly, you still may be faced with an issue due to the number of row headers you're using. So based on the results I got as previously stated here, the empty fields in a record are not nulls, they're a splitting of the data for whatever reason. Then the answer may be to use a Union query on your ct query to eliminate the empty spots.
As for your stated goal, I don't see that as being possible due to the fact that all it seems to take is a period in a comments field to mess things up. Seems to me the goal should be to eliminate all factors that contribute to the undesired result, be that table design, table relationships (you have none in this case) or whatever else one might try.
That's about all I can think of.