Skip to Main Content
  • Questions
  • Unable to create chart in APEX as column mapping says "wrong data type" for value

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, Olivia.

Asked: March 04, 2023 - 3:54 am UTC

Last updated: March 08, 2023 - 1:58 pm UTC

Version: APEX 22.2.2

Viewed 1000+ times

You Asked

Hello!

I am looking to display a percentage with a donut chart in APEX. The percentage is found by dividing two select count sql statements by each other. I used the following sql statement to find this value, which works:

SELECT CONCAT(CAST((YES_INT * 100.0) / TOTAL_INT AS VARCHAR(20)), '%')
FROM
 (SELECT COUNT(OPP) AS YES_INT
  FROM ACTION_ITEM
  WHERE Opp = 'yes'),
 (SELECT COUNT(TITLE) AS TOTAL_INT
  FROM ACTION_ITEM)


However, when selecting the value in the column mapping section in order to create the chart, I receive a "wrong data type" error. I am not sure how to alter my SQL to be the correct data type to create a chart in APEX.


Please let me know if there is any additional background information I need to provide. Thank you very much!

and Chris said...

Stop casting the result to a string! The values for this chart must be numbers.

I'm unsure exactly what you're trying to show, grouping by OPP may be what you're looking for:

SELECT Opp, COUNT(TITLE) AS TOTAL_INT
FROM ACTION_ITEM
GROUP BY Opp


You can make the values display as percentages by setting the series to:

Series -> Label -> Display As -> Label - Percentage

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

APEX

Keep your APEX skills fresh by attending their regular Office Hours sessions.