So for example I want to show the count of each item purchased in the past 30 days. In the same table I would like to see side by side the count for the past 30 days, and the previous 30 days. This data is coming from a MongoDB.
So columns in a table like this:
Item Name, Current Sales, Previous Sales
This is simple to do as 2 separate panels, somewhat simple if I hard code the previous 30 days instead of being automatically based on the dashboard date range. But to base it off the dashboard, I have not found a good way to manage it. It was quite complicated trying to get it working correctly.
Am I missing something? Is there a good way to handle this type of scenario?
can you union the two collections?
so this is more of a mongo query issue than a grafana issue
might be better served on a mongodb forum
To clarify more, I’m asking for a way to get the previous period date. I have not been able to find an easy way to do so through variables or anything else. Instead I had to do the current time, minus the end minus the start. Which starts making the queries a bit convoluted. Which is this
"$expr":{
"$and":[
{"$gte":["$Date", { "$subtract": [ {"$toDate":"${__from:date}"}, { "$subtract": [ { "$toLong": "${__to}" }, { "$toLong": "${__from}" } ] }] }]},
{"$lte":["$Date", { "$subtract": [ {"$toDate":"${__to:date}"}, { "$subtract": [ { "$toLong": "${__to}" }, { "$toLong": "${__from}" } ] }] }]}
]
Also I was kinda hoping Grafana had an easier way to manage this built in.
I already got something functional, but not looking forward to setting up other graphs needing similar logic.
Ideal scenario from Grafana would be a way to reuse the same query twice, with it passing the different dates in to the query, and then combining the results into one set for the table. In practice, trying to do it yourself becomes a lot more complicated.