That's just a question in terms of it's generally possible or not.
CubeJs can call Postgres functions without an issue. But is there a way to pass a list of selected measures into the function? I've tried to use queryRewrite and queryTransformer, but they don't help here at all, as I can operate with dimensions/measures only and not with the "sql" parameter of the cube itself.