Custom SQL Measure syntax


#1

Been having a bit of trouble with parse errors with creating some different custom measures. Tried following the docs and taking a traditional approach, but hasn’t been working. Here’s an example of something we would frequently want to do, and trying it on a table chart:

Expected syntax for desired result to be labeled as "stat_count_avg"
SELECT AVG(stat_count) * COUNT(DISTINCT(share_id)) AS stat_count_avg

This returns the correct value (but with the header long header ):
AVG(stat_count) * COUNT(DISTINCT(share_id))

Fails:
SELECT AVG(stat_count) * COUNT(DISTINCT(share_id)) AS stat_count_avg
AVG(stat_count) * COUNT(DISTINCT(share_id)) AS stat_count_avg
SELECT AVG(stat_count) * COUNT(DISTINCT(share_id)) FROM table_name
(tried many others)

Suggestions?


#2

Hi

I think the best way to think of the custom measure is what you could syntactically place between a

SELECT and an AS

The custom measure will not be able able to rename the column as the AS is already being added by the Immerse layer.

Hope this helps