idejjedi2
asked on
MS Access Query - Percentages
Hey Experts,
Trying to calculate the percentages. So far I have a code that counts the results and displays them. This code is here:
SELECT LitOrigName.litName AS Originator, Count(LitOrigName.litName) AS [Number Of Members]
FROM MemberMasterTable INNER JOIN LitOrigName ON FellowshipMasterTable.litI D = LitOrigName.litID
GROUP BY LitOrigName.litName;
Now, I would like to calculate the percentages of each result. The Originator column produces 5 different results, with the first result displaying a count of 200 out of a total of 549. I want to create a percentage column that displays the results, so the first result would produce a percentage result of 36.4% from 200/549.
Trying to calculate the percentages. So far I have a code that counts the results and displays them. This code is here:
SELECT LitOrigName.litName AS Originator, Count(LitOrigName.litName)
FROM MemberMasterTable INNER JOIN LitOrigName ON FellowshipMasterTable.litI
GROUP BY LitOrigName.litName;
Now, I would like to calculate the percentages of each result. The Originator column produces 5 different results, with the first result displaying a count of 200 out of a total of 549. I want to create a percentage column that displays the results, so the first result would produce a percentage result of 36.4% from 200/549.
ASKER
Hey Rey,
Sorry. I accidentally cut and paste a code that I was working on and not the already functioning code. It is as follows and is functioning properly.
SELECT LitOrigName.litName AS Originator, Count(LitOrigName.litName) AS [Number Of Fellows], SUM(LitOrigName.litNam) AS [Totals]
FROM FellowshipMasterTable INNER JOIN LitOrigName ON FellowshipMasterTable.litI D = LitOrigName.litID
WHERE FellowshipMasterTable.litI D Is Not Null
GROUP BY LitOrigName.litName;
Sorry. I accidentally cut and paste a code that I was working on and not the already functioning code. It is as follows and is functioning properly.
SELECT LitOrigName.litName AS Originator, Count(LitOrigName.litName)
FROM FellowshipMasterTable INNER JOIN LitOrigName ON FellowshipMasterTable.litI
WHERE FellowshipMasterTable.litI
GROUP BY LitOrigName.litName;
ASKER
Sorry. I accidentally cut and paste a code that I was working on and not the already functioning code. It is as follows and is functioning properly.
SELECT LitOrigName.litName AS Originator, Count(LitOrigName.litName) AS [Number Of Fellows]
FROM FellowshipMasterTable INNER JOIN LitOrigName ON FellowshipMasterTable.litI D = LitOrigName.litID
GROUP BY LitOrigName.litName;
SELECT LitOrigName.litName AS Originator, Count(LitOrigName.litName)
FROM FellowshipMasterTable INNER JOIN LitOrigName ON FellowshipMasterTable.litI
GROUP BY LitOrigName.litName;
try this
Select A.Originator,A.[Number Of Fellows],A.Totals, Format(A.[Number Of Fellows]/A.Totals,"Percent ") As Percentage
From
(
SELECT LitOrigName.litName AS Originator, Count(LitOrigName.litName) AS [Number Of Fellows], DCount("*","LitOrigName"," litName=" & FellowshipMasterTable.litI D ) AS [Totals]
FROM FellowshipMasterTable INNER JOIN LitOrigName ON FellowshipMasterTable.litI D = LitOrigName.litID
WHERE FellowshipMasterTable.litI D Is Not Null
GROUP BY LitOrigName.litName;
) As A
.
Select A.Originator,A.[Number Of Fellows],A.Totals, Format(A.[Number Of Fellows]/A.Totals,"Percent
From
(
SELECT LitOrigName.litName AS Originator, Count(LitOrigName.litName)
FROM FellowshipMasterTable INNER JOIN LitOrigName ON FellowshipMasterTable.litI
WHERE FellowshipMasterTable.litI
GROUP BY LitOrigName.litName;
) As A
.
ASKER
I copied and pasted your code and returned a "Your query does not include specified expression 'DCount("*"<LitOrigName", "litName="& FellowshipMasterTable.litI D) as part of an aggregate function.
In response to this, I added FellowshipMasterTable.litI D into the GROUP BY Clause and it produces the following results.
reyoutput1.jpg
In response to this, I added FellowshipMasterTable.litI
reyoutput1.jpg
can you upload a copy of your db...
ASKER
I cannot. Some sensitive information is involved. I am somewhat new to SQL and not an expert in SQL, I am surprised that their is not an easy way to perform this type of query. Seems like it would be a common question for businesses and organizations. I did a general google search and noted some similar questions and answers in different database platforms (MySQL, MS SQL) that all came up with different and elaborate solutions. Just surprised. But again, I am not an expert.
Thanks for trying... If I come up with a solution soon, I will post it to this for everyone to see...
Thanks for trying... If I come up with a solution soon, I will post it to this for everyone to see...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Could not get any of the other code to process the information correctly. My code finally gave the results I was trying to get. Rey's and his contributions involving sub queries was helpful, but even when adapting his code, it was not producing results required.
this line doesn't look right
FROM MemberMasterTable INNER JOIN LitOrigName ON FellowshipMasterTable.litI