Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to calculate the percentage of employee type in OTBI Report?

Hi I have tried a lot of methods using count and sum. An example table can be the following:

Name Employee Type Percentage
First E 66.6
Second E 66.6
Third E 66.6
Fourth E 66.6
Fifth C 33.3
Sixth C 33.3

I have tried using column formula like this: COUNT(COUNT("Worker"."Person Number") by "Worker"."Assignment Type")100 /COUNT()

But I believe that the first count shouldn’t be there and if I use it without it, OTBI gives me a syntax error. Please help me out with this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You may try using analytic functions here:

SELECT Name, "Employee Type",
       100.0 * (COUNT(*) OVER (PARTITION BY "Employee Type") /
                COUNT(*) OVER () ) AS Percentage
FROM yourTable
ORDER BY "Employee Type", Name;

Here is a demo for Oracle.

If for some reason you can’t use analytic functions, then a join approach also works here:

SELECT t1.Name, t1."Employee Type",
       100.0 * t2.cnt / (SELECT COUNT(*) FROM yourTable) AS Percentage
FROM yourTable t1
INNER JOIN
(
    SELECT "Employee Type", COUNT(*) AS cnt
    FROM yourTable
    GROUP BY "Employee Type"
) t2
    ON t2."Employee Type" = t1."Employee Type"
ORDER BY "Employee Type", Name;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading