Sorting on custom expressions column

I found a lot of issues about it sort expression metrics, but no one has any answer about it.

So I have this column that is a metric with custom expression, and I NEED to sorting this result but the option doesn't show for me, neither in heading column and neither in edition of question.

Someone could help me?

My configs:
{
"browser-info": {
"language": "pt-BR",
"platform": "Win32",
"userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36",
"vendor": "Google Inc."
},
"system-info": {
"java.runtime.name": "OpenJDK Runtime Environment",
"java.runtime.version": "11.0.5+10",
"java.vendor": "AdoptOpenJDK",
"java.vendor.url": "https://adoptopenjdk.net/",
"java.version": "11.0.5",
"java.vm.name": "OpenJDK 64-Bit Server VM",
"java.vm.version": "11.0.5+10",
"os.name": "Linux",
"os.version": "4.4.0-128-generic",
"user.language": "en",
"user.timezone": "GMT"
},
"metabase-info": {
"databases": [
"postgres",
"sqlserver"
],
"hosting-env": "unknown",
"application-database": "postgres",
"run-mode": "prod",
"version": {
"date": "2020-01-13",
"tag": "v0.34.1",
"branch": "release-0.34.x",
"hash": "265695c"
},
"settings": {
"report-timezone": "America/Sao_Paulo"
}
}
}

Hi @puglisi

Can you try this possible workaround/temporary-solution?

  • At the end of your query, add a Custom Column with the value: Mkbe and the name: Mkbe2
    (ie make a copy of your Custom Expression variable)

  • Now try to add a Sort using Mkbe2

Summarizing by a Custom Expression

You can't sort by the Custom Expression variable avg_quantity

Creating a Custom Column clone of the Custom Expression variable

Sorting by the Custom Column clone

And magically, the original Custom Expression variable also appears as a sort option?! :astonished:

@morganhankins

Thank you for the answer, but I can't create a custom column using the custom expression.

The custom expression:

Any help?

Are you trying to create a the custom column using the small +col button at the top or the larger ‘Custom Column’ button at the bottom?

Can you make sure you are using the ‘Custom Column’ button at the bottom?

@morganhankins
Thank you for the answer!

The expression show to me, but when I used I go to Pre-Visualize (at the red marked) to see how the results are...

..I got this error =((

If I see the SQL, the MKBE column dont exist for real, because the alias of expression is "expression"

Do you know how to fix this?

I think you are correct (and I am wrong :slightly_smiling_face:)

I can reproduce the error you get.
It looks like issue #6239 is still broken.

I don’t know =(
But I still can not sort a custom metric, and that is really bad for my solution =(

If I create a custom column and give the 'expression' name for my custom metric, I could sort the results, but only with the custom column.
I have a lot of filters for this question, and the problem is it only information that I group on my metric is used on filter, others filters is no avaliable anymore. =(

now I have only one filter
image

the way it was before
image