So I have this table:
ID sale_date item price
-------------------------------
1 2022-11-01 apple 2.11
2 2022-11-02 apple 2.61
3 2022-11-03 apple 2.91
4 2022-11-04 apple 2.51
5 2022-11-01 orange 3.23
6 2022-11-02 orange 2.75
7 2022-11-03 orange 3.01
8 2022-11-04 orange 3.51
9 2022-11-01 banana 1.93
10 2022-11-02 banana 2.22
11 2022-11-03 bananna 2.13
12 2022-11-04 banana 1.53
I am trying to create a query that will display in a Grafana time series graph measuring the price for apple, orange and bananas overtime.
my query:
SELECT
$__time(sale_date),
item,
price
from mytable
group by sale_date, item, price
I am trying to achieve a time series similar to this:
any help is appreciated :)
This will be good start - aggregated avg price per day:
SELECT
$__timeGroupAlias(sale_date, '1d'),
item as "metric",
AVG(price) AS "value"
FROM mytable
WHERE
$__timeFilter(sale_date)
GROUP BY 1, 2
ORDER BY 1
You may still need to tweak it, because your sale_date datatype is unknown. Eventually, you may need different macro.
Related
i have a table with detail transaction for lot. Lot are harvest and store before being ship.
Date lot transaction qty
5 sept 3 store 300
8 sept 3 ship -50
10 oct 3 ship -20
15 nov 3 ship -20
...
If i want the inventory for a specific moment, i simply sum between to date
I would like a query that can give me a sum from store to a specific month throught the entirr year like:
Lot sept to oct to nov ...
3 250 230 210 ...
Select lot, sum(qty) from ... where (date > 1 sept and date < 1 oct) as sept, (date > 1 sept and date < 1 nov)... group by lot
I did'nt find anything or figure out how to do it i a simple query.
Regards
Obtain one table with a query where is see the evolution of quantity over the year.
month name fruit eaten amount paid
Jan-19 john apple 3
Jan-19 jim orange 7
Jan-19 king apple 6
Feb-19 john berry 5
Feb-19 jim mango 7
Feb-19 king pawpaw 8
Mar-19 john apple 5
Mar-19 jim melon 7
Mar-19 king lemon 9
solution I want:
Name latest fruit eaten (Mar-19) Year to date Total spent by Name
john apple 13
jim. melon 21
king lemon 23
Please I want to summarize the values based in the image only include the maximum or latest value of one column.
Thanks
Place month filter and select March, now place name and fruit on rows.
Create a calculated field amount and write below:
{ FIXED [fruit]:SUM([amount])}
Place it on marks
Edit-------------------------------------------------------------------
calculated field:
I am trying to create a Google Spreadsheet for my sales for my business, that is happening on several different online portals e.g. Amazon, eBay, My Website, etc.
This is what I created:
But if I create this way then I do not get any graphs, which I really do need.
Though I tried other ways too, in which I had the portals in row 1 and dates in Column A, but in that case, I can have only one parameter, either No of Sales or Total Sales (rupees)
And the graph for this comes out nicely:
However, in this case, I would have to create separate sheet to record the Sales in Amount.
Is there a way to work this situation out, where I can create one table, and have graphs showing me the data as required as well?
This is a good application for Pivot Tables. Starting with your source data, you can either create pivot tables from the GUI (Data > Pivot Tables...) or by a formula using the QUERY function.
For example, this formula will create a table with portals in separate columns:
=QUERY(A:D,"SELECT B,SUM(C) WHERE A != '' GROUP BY B PIVOT A")
Note: A chart of this data requires that all cells be filled with numbers, so it's necessary that your source data includes zero values for portal/days with no sales, as shown in this sample data:
A B C D
Portal Date No of Sales Total Sales
Amazon June 18 33 45.62
Flipkart June 18 2 2.64
Biocarve June 18 3 4.32
Ebay June 18 0 0.00
Amazon June 19 22 37.01
Ebay June 19 2 3.52
Flipkart June 19 0 0.00
Biocarve June 19 0 0.00
Biocarve June 20 5 6.47
Flipkart June 20 1 1.45
Amazon June 20 8 10.69
Ebay June 20 0 0.00
The pivot table output is:
Date Amazon Biocarve Ebay Flipkart
6/18/2016 33 3 0 2
6/19/2016 22 0 2 0
6/20/2016 8 5 0 1
And the chart:
Likewise, this formula:
=query(A:D,"select B,SUM(D) WHERE A != '' GROUP BY B PIVOT A")
...tabulates the total sales, with this result:
Date Amazon Biocarve Ebay Flipkart
6/18/2016 45.62 4.32 0.00 2.64
6/19/2016 37.01 0.00 3.52 0.00
6/20/2016 10.69 6.47 0.00 1.45
You can also get all the summary data into one table, and produce a chart from that. (You need to customize your chart series to use left & right axes.)
The query:
=query(A:D,"select B,SUM(C),SUM(D) WHERE A != '' GROUP BY B PIVOT A")
The resulting table:
And an example chart from that table:
I have two tables in a stage-gate project management system, one (simplified) table containing a project ID and actual gate dates for each gate, 1-5. In the other I have a historic record of all forecast data; Projected Revenue, Projected Margins, Forecast Year, etc. Each time a forecast is updated, it records the new forecast values, the time stamp of the change, and the project ID. The requirement is to retrieve all metric values for the latest update prior to the actual gate date recorded in the first table. An example, Project 100 has a Gate 2 date of 2014-12-18. I need to retrieve the most recent values prior to that date.
Gate Date Table:
ProjectID InternalGate2
--------- -------------
100 2014-12-18
2000 2013-01-15
Historic Metric Table:
ProjectID Metric MetricYear LastUpdated MetricValue
--------- ------ ---------- ----------- -----------
100 Sales 2015 2013-09-05 125000
100 Sales 2016 2013-09-05 230000
100 GM 2015 2013-09-05 .48
100 GM 2016 2013-09-05 .49
100 Sales 2015 2014-05-26 200000
100 Sales 2016 2014-05-26 300000
100 GM 2015 2014-05-26 .50
100 GM 2016 2014-05-26 .51
100 Sales 2015 2015-01-28 300000
100 Sales 2016 2015-01-28 400000
100 GM 2015 2015-01-28 .55
100 GM 2016 2015-01-28 .56
2000 Sales 2014 2012-11-23 200000
2000 Sales 2015 2012-11-23 300000
2000 Sales 2016 2012-11-23 310000
2000 GM 2014 2012-11-23 .75
2000 GM 2015 2012-11-23 .77
2000 GM 2016 2012-11-23 .77
2000 Sales 2015 2013-02-11 450000
2000 Sales 2016 2013-02-11 450000
2000 Sales 2017 2013-02-11 500000
2000 GM 2015 2013-02-11 .68
2000 GM 2016 2013-02-11 .69
2000 GM 2017 2013-02-11 .70
For this example the results set would be the four rows for Project 100 with the LastUpdated Date of 2014-05-26 as this was the last update prior to 2014-12-18 and the first six rows of data for Project 2000 updated 2012-11-23.
Any guidance would be greatly appreciated.
The CTE could be a subquery if you prefer, but this works, basically just using two joins.
;WITH CTE as
(select h.ProjectID,MAX(LastUpdated) as LatestUpdate
from Historic h
inner join Gate g
on h.ProjectID = g.ProjectID
and h.LastUpdated <= g.InternalGate2
group by h.ProjectID)
select ProjectID,LastUpdated
from Historic h
inner join CTE c
on h.ProjectID = c.ProjectID
and h.LastUpdated = c.LatestUpdate
I'm using SAS 9.3
I need to create a way to sum up by week total, and I have no idea how to do it. So basically I have a year list of dates (left column below) with a total from that date (the right column). Our week goes from Friday to the previous Thursday (e.g. Thursday Oct 17 through Friday the Oct 25th).
An issue I also have is as you see the dates on the left are not completely daily and don't always have a Thursday date before the last Friday date. Would any know a way to add these weeks up - Week 1, Week 2, etc etc ...?
Thanks for any help that can be provided
2013-01-01 3
2013-01-02 8
2013-01-03 8
2013-01-04 10
2013-01-06 1
2013-01-07 10
2013-01-08 14
2013-01-09 12
2013-01-10 8
2013-01-11 9
2013-01-12 1
2013-01-14 12
2013-01-15 8
2013-01-16 5
2013-01-17 15
2013-01-18 7
2013-01-20 1
Trivial way:
data want;
set have;
weekno = ceil((date-'03JAN2013'd)/7);
run;
IE, subtract the first thursday and divide by 7, (so 1/1-1/3 is weekno=0).
INTCK function is also adept at calculating this. The basic structure is
weekno=intck('WEEK.5','04JAN2013'd,date); *the second argument is when you want your first week to start;
WEEK means calculate weeks, # on left side of decimal is multiple week groups (2 week periods is WEEK2.), on right side is shift index (from the default sunday-saturday week).
You could also create a format that contained your weeks, and use that.