Aggregations on Individual "Grouped By" Fields AND Showing the records within each group

@spacepluk Without knowing exactly what you’re trying to do, there’s a couple of issues open for windowing, which might be available in 0.34 (no guarantees) - upvote by clicking :+1: on the first post of each issue:
https://github.com/metabase/metabase/issues/9393
https://github.com/metabase/metabase/issues/8977

I'm not sure if these issues are about the same use-case @Blake explained. For example, if I have data that looks like this:

I would like to be able to calculate the average amount per entityId per context per hour/day/etc. while keeping the ability to drill down from the visualization to see the original records.

I think this is a pretty common use-case (e.g. avg sales per customer per product type over time) and is very straight-forward to do in Tableau but I haven't managed to figure out a way to do it in Metabase.

@spacepluk
Maybe I'm completely misunderstanding, but wouldn't you just summarize average by customer, product and timestamp?
Here's an example from the Sample Dataset:

It’s probably me who is failing to explain this clearly and/or misunderstanding things. Please correct me if I’m wrong.

Your example would give the average total per order which in my dataset would be equal to the product price (no discounts, no quantity, one record per transaction). But the number I want to get is the average spent per user per context per time slice. So if a user buys the same thing repeatedly in the same slice that should raise the number (looking for cheaters in my game).

The orders dataset in the examples is not really a good one to illustrate this. If you want I can prepare a testcase with some data (csv?) and maybe a couple of videos.

@spacepluk It might be helpful with how/what you’re doing it on Tableau. And if you can quickly dish up some CSV, then that’ll be great too. It’s not always easy to understand other people’s data :wink:

Sorry for the delay, I got sidetracked with other stuff. Here’s the video and the csv:


The part I can’t figure out how to do in metabase is around the middle of the video. Where I type SUM(Amount)/COUNTD(EntityId) and I can still drill down to the actual registers from the chart.

@spacepluk
Okay, so let's see if I understood this correctly. I just did this in the Sample Dataset, since your data looks very similar. Seems like you're just looking for Custom Expression:




You could even do it with a joined table:

Wow, I have no idea how I missed that! This is exactly what I needed, thanks! :slight_smile:

I’m not sure if it’s related to this, but when I drill down on one of the chunks in the stacked bar chart it shows data for the previous day.

@spacepluk Which version of Metabase? There are a lot of fixes to timezone in the last couple of versions, and there will be even more in the upcoming 0.34.0
Can you reproduce with Sample Dataset, then please describe how?
I remember another issue about drill doing something it shouldn’t , but I need to be able to reproduce, to better understand and search for issues.

@spacepluk I think you might be seeing this issue https://github.com/metabase/metabase/issues/11251

Go give it a thumbs up and hopefully it’ll be addressed in the Timezones release which it’s currently tagged for.

@flamber I added a Sample Dataset reproduction to that issue but it didn’t seem to work for you guys, but I think my screenshots show that it’s happening in my setup. Looking forward to the timezones release as this issue is really turning some of my key users off.

@notrom Are you still seeing this (even with Sample Dataset) on 0.33.6? I'm on master right now, which has some more timezone fixes, but I cannot reproduce. Can you post your Diagnostic Info from Admin > Troubleshooting, since it contains some timezone info.

Yes this is still a problem for me. This used to work so well, I can't put my finger on exactly which version it changed at.

Here's v0.33.6 after "zoom in" on November 2019

Here's the diagnostic info (Chrome or Firefox makes no difference):
{
"browser-info": {
"language": "en-US",
"platform": "Win32",
"userAgent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:70.0) Gecko/20100101 Firefox/70.0",
"vendor": ""
},
"system-info": {
"java.runtime.name": "Java(TM) SE Runtime Environment",
"java.runtime.version": "1.8.0_101-b13",
"java.vendor": "Oracle Corporation",
"java.vendor.url": "http://java.oracle.com/",
"java.version": "1.8.0_101",
"java.vm.name": "Java HotSpot(TM) Client VM",
"java.vm.version": "25.101-b13",
"os.name": "Windows 7",
"os.version": "6.1",
"user.language": "en",
"user.timezone": "Pacific/Auckland"
},
"metabase-info": {
"databases": [
"sqlserver",
"postgres",
"h2"
],
"hosting-env": "unknown",
"application-database": "postgres",
"run-mode": "prod",
"version": {
"tag": "v0.33.6",
"date": "2019-11-19",
"branch": "release-0.33.x",
"hash": "be1e0e1"
},
"settings": {
"report-timezone": "Pacific/Auckland"
}
}
}

I changed my report timezone to match yours, @notrom, (Pacific/Auckland) and the same scenario looks correct to me on master, so this will likely be fixed for you in 0.34. One difference I'm noting is that the SQL now includes with timezone:

Thanks, I’ll stick it out till 0.34. Hopefully that’ll resolve this one.

yeah, I think you’re right @notrom. I did some tests grouping by month an I still get the previous one. It doesn’t look like a TZ issue from what I can gather. I’ll add another reproduction to that github issue.

I forgot to say that I’m using the metabase app (0.33.6.0) on macOS 10.14.6, and PostgreSQL 12.

@maz is there a jar file for the master branch? I’d be more than happy to test this but don’t have a suitable environment here to build it myself at this time.

@notrom I don’t know of any master JARs, but there’s a Docker, where you should either use Docker or extract the file /app/metabase.jar from the image with docker cp.
https://hub.docker.com/r/metabase/metabase-head/tags

We’re aiming to do a release candidate build by the end of the week, so that would probably be a good time to try it out. You can watch this page: https://github.com/metabase/metabase/releases