The revised code above seems to be working properly now, thank you!
If you wouldn't mind, could you explain to me what "D" and "X" are doing in the code?
Also, I tried using your code for my other charts, which do the same thing as the riskRating chart, only for different columns (all of which also only contain "high", "medium", or "low"). All I did was change "riskRating" to the name of the corresponding field. I did this for two charts, one for "residualRisk" and the other for "ncmRisk". The "residualRisk" chart isn't displaying percentages properly, the same issue you just fixed on the "riskRating" chart. The "ncmRisk" chart is displaying percentages properly, but unlike the other two charts it isn't setting "low" to 0 instead of null, so the coloring is off again.
This is really strange, considering all I did was create new Union Queries (1 for "residualRisk", 1 for "ncmRisk") using the same sql that you posted, changing "riskRating" to the corresponding field name, and got 2 different issues. I was really hoping I was done struggling with charts after your code worked perfectly for the first one.
Below is the sql and row source for each of the charts, if you can see any issues.
Residual Risk:
Code:
SELECT tScenarios.residualRisk, IIf([residualRisk]="Low",1,IIf([residualRisk]="Medium",2,IIf([residualRisk]="High",3))) AS Expr1, IIf([Expr1]=1,"Low",IIf([Expr1]=2,"Medium",IIf([Expr1]=3,"High"))) AS Expr2, "D" AS Source
FROM tScenarios
UNION SELECT "Low", 1, "Low", "X" FROM tScenarios
UNION SELECT "Medium", 2, "Medium", "X" FROM tScenarios
UNION SELECT "High", 3, "High", "X" FROM tScenarios;
Code:
SELECT qOverallResidual.[residualRisk], Count(qOverallResidual.[Expr2]) AS CountOfExpr2 FROM qOverallResidual GROUP BY qOverallResidual.[residualRisk] HAVING (((qOverallResidual.[residualRisk])<>""));
ncmRisk
Code:
SELECT tScenarios.ncmRisk, IIf([ncmRisk]="Low",1,IIf([ncmRisk]="Medium",2,IIf([ncmRisk]="High",3))) AS Expr1, IIf([Expr1]=1,"Low",IIf([Expr1]=2,"Medium",IIf([Expr1]=3,"High"))) AS Expr2, "D" AS Source
FROM tScenarios
UNION SELECT "Low", 1, "Low", "X" FROM tScenarios
UNION SELECT "Medium", 2, "Medium", "X" FROM tScenarios
UNION SELECT "High", 3, "High", "X" FROM tScenarios;
Code:
SELECT qNcmRisk.[ncmRisk], Count(qNcmRisk.[Expr2]) - 1 AS CountOfExpr2 FROM qNcmRisk GROUP BY qNcmRisk.[ncmRisk] HAVING (((qNcmRisk.[ncmRisk])<>""));