InfluxDB count same string values for a timerange - influxdb

I've set up the following InfluxDB measurement called ratio with one fieldKey called "name"
--------------------------------------------------
| time | name |
--------------------------------------------------
| 1481274571179850400 | current_assets |
--------------------------------------------------
| 1481274571179850401 | othervalue |
--------------------------------------------------
| 1481274571179850402 | othervalue |
--------------------------------------------------
| 1481274571179850403 | current_assets |
--------------------------------------------------
| 1481274571179850404 | othervalue |
--------------------------------------------------
There are about 20 different names.
Depending on what is called on the backend I write one line with the given name (e.g. current_assets, othervalue, ...) for statistic.
This works well and I get the table above.
Now I'd like to create one query (in grafana)
hits per timerange for a single name
e.g.
251 "current_assets" entries the last 24 hours
21 "other value" entries the last 6 hours
I have tried different things here but I can not make it.
Does somebody have any idea how such a query can look?
Thanks a lot

I'd recommend changing name to a tag and having a field value that either stores an integer or a bool. That way you can issue queries like
SELECT count(value) FROM ratio WHERE time > now() - 24h GROUP BY name

Related

Count values in another sheet in Google Spreadsheet where sheet name is a cell value using ARRAYFORMULA

I have a Google Spreadsheet with multiple sheets. I cannot share a sample because this is G-Suite Enterprise and it is locked. If absolutely needed I can create a dummy one on my personal Gmail.
One of the sheets has a list of lookup values and sheet names. I am trying to come up with an ARRAYFORMULA that will count the # of times Lookup Value shows in column A of Lookup Sheet Name.
| Lookup Value | Lookup Sheet Name | Count |
|--------------|-------------------|-------|
| one | Primary | ... |
| two | Secondary | ... |
| three | Stuff | ... |
| ... | Primary | ... |
| ... | ... | ... |
I came up with this formula For C2 but it does not work. I don't exactly know why but it shows 1 for every lookup value or just one row with 1.
=ArrayFormula(IF(A2:A <> "", COUNTIF(INDIRECT(B2:B & "!A2:A"), A2:A), ))
I do not want to use Google Apps Script to solve this.
Here is one possible solution that combines the values of the different sheets in one by adding a second column with constant value (the name of the seet for example).
=ArrayFormula(
IF(A:A<>"",
COUNTIFS(
{
FILTER('sheet A'!A:A,NOT(ISBLANK('sheet A'!A:A)));
FILTER('sheet B'!A:A,NOT(ISBLANK('sheet B'!A:A)))
},"="&A:A,
{
FILTER(IF(ISBLANK('sheet A'!A:A),,"sheet A"),NOT(ISBLANK('sheet A'!A:A)));
FILTER(IF(ISBLANK('sheet B'!A:A),,"sheet B"),NOT(ISBLANK('sheet B'!A:A)))
},"="&B:B
),
)
)

Count unique cells and display them in column

I am building a list of gigs I attended and I want to count how many times I've seen each band.
I know about UNIQUE, but because I keep each band in separate column it just copies each row.
Given the table (or screenshot of real data):
| Date | Venue | Bands |
|----------|--------|--------|--------|--------|--------|--------|
| 02.02.17 | Venue1 | Band A | Band B | Band C | Band D | Band E |
| 02.07.17 | Venue3 | Band D | Band C | | | |
The output I want:
| Band | Attended |
| | (times) |
|--------|----------|
| Band A | 1 |
| Band B | 1 |
| Band C | 2 |
| Band D | 2 |
| Band E | 1 |
I can change structure if needed.
What happens after using UNIQUE: https://i.stack.imgur.com/qmszk.png
Thanks in advance.
Step 1. Get list of all unique bands in one column, one per row
=ArrayFormula(UNIQUE(TRANSPOSE(SPLIT(CONCATENATE(Gigs!D2:Z&CHAR(9)); CHAR(9)))))
Step 2. Place this formula in next column, and drag it down
=SUM(COUNTIF(Gigs!D:Z; E2))
Transform your data to a simple table format in order to make easier to do data-analysis.
A simple table use the first row for column headers a.k.a. fields and has one and only one column for each entity, let say only one column for band names.
The above could be done in a single but complex formula hard to debug, so it's better to start by doing this using simple formulas and once you are certain that all is working fine, think about making a complex formula or writing and script.
Related
Unpivot Matrix to Tabular. Using counts of two variables into individual rows
Generate a list of all unique values of a multi-column range and give the values a rating according to how many times they appear in the last X cols
Normalize (reformat) cross-tab data for Tableau without using Excel
How do you create a "reverse pivot" in Google Sheets?

Is it possible to aggregate expenses per category in google spreadsheets

I am trying to track my expenses manually. I looked for already built options and I did not find anyone I knew how to use or that it covered what I want to do.
What I am doing is basically manually write down what appears in my bank, with the intention of categorizing the expenses myself, since as I said, I did not find a better way to do it.
So it looks like this:
Cinema | 11.95
Going out (restaurant1) | 26.55
Netflix | 13.95
Weekly purchases | 72.66
Going out | 9
Bill (type) | 29.16
Rent month | 650
Going out | 26.55
Bill (type2) | 66.45
Compra semanal | 81.09
Bill (type3) | 21.1
( "|" is used as if it were two different cells) And what I would like now is to take the generic name that I gave the cathegory (without the parenthesis, I am using those for myself, so I can track where was the money spent, more specifically), and how much was spent.
In programming I would do this with a regex for the left cell, and aggregating by name, and then plotting the data somehow. I am unsure if this is even possible, maybe I should use Excel but Drive has the cloud advantage so I would like some help as to where to start, I do not need anything too fancy, a new column with the category and the total spent would work wonders for me, but I have not found an easy way of doing it (and I doubt I am doing something so complex, so I assume I am thinking this the wrong way). Best case scenario, I manage to plot it all so it is more visual, or I can have several columns plotted against each other (I have different columns for shared expenses, personal expenses, and so on).
If you can put the category (e.g. Bill) in a separate column from your details (e.g. type 1) then the Pivot Table feature is exactly what you need.
Start with something like this (the heading on each column is important):
Category | Details | Amount
Cinema | | 11.95
Going out | restaurant 1 | 26.55
Netflix | | 13.95
Weekly purchases | | 72.66
Going out | | 9
Bill | type | 29.16
Rent month | | 650
Going out | | 26.55
Bill | type2 | 66.45
Compra semanal | | 81.09
Bill | type3 | 21.1
Then click Data, Pivot Table. Under Rows, click Add and choose Category. Under Values, click Add and choose Amount. You should see a table like this:
Category | SUM of Amount
Bill| 116.71
Cinema | 11.95
Compra semanal | 81.09
Going out | 62.1
Netflix | 13.95
Rent month | 650
Weekly purchases | 72.66
Grand Total | 1008.46
Any unique value in the Category column creates a new row in the pivot table.
Further Details: https://support.google.com/docs/answer/1272900
=ARRAYFORMULA(QUERY({REGEXREPLACE(TRIM(A:A)," \(.*\)",),B:B},"Select Col1,sum(Col2) where Col1 is not null group by Col1"))

Structuring a query between multiple tabs to join values by name

I'm trying to write a SQL query in Google Sheets to try and get data for "matching" results from two different tabs, but running into some trouble.
This is a sheet that's basically an automated scoring engine for instructors who take a two-part test (written and practical). After the results are entered, I'd like to use some SQL to take the results from the two tabs and collate them into a final score.
Link to the sheet in question.
There's a "Practical Scores" tab (which takes all the data from the associated Google Form), and a "Written Scores" tab. I'd like to get the name of the instructors who match in both those tabs, and give the associated score for them, but I'm mostly having trouble with writing the correct SQL.
Most of what I'm trying to do is working fine. I'm able to pull the final practical scores via the following SQL:
=query(PracticalScores!A2:E, "select A, count(E),SUM(E)/3 group by A")
I can also pull the written scores as follows:
=query('Written Scores'!B2:C,"select B,C")
But I want the intersection of the two as well, and that's where I'm running into problems.
=query(A8:E, "select A,C,D where A = E")
will simply return the rows where the names match up, and I want the instances where the names match up, regardless of whether the rows do.
That is, I want all the rows where the names match from tab 1 to tab 2 and not just the few rows that happen to line up perfectly.
If I'm not explaining this well, please let me know and I can provide additional information. Any assistance would be very greatly appreciated!
Since the query function does not support joins, this can't all be done in one query. Instead, the following device can be used:
=arrayformula(vlookup(name column, table, # of column to extract, False))
For example, suppose I have a table
+---+-------+---+
| | A | B |
+---+-------+---+
| 2 | Jim | 3 |
| 3 | Sarah | 4 |
| 4 | Bob | 5 |
+---+-------+---+
to which I want to add another column, taking it from
+---+-------+---+
| | E | F |
+---+-------+---+
| 2 | Sarah | 9 |
| 3 | Bob | 8 |
| 4 | Jim | 7 |
+---+-------+---+
The basic idea is to put in cell C2 the formula
=arrayformula(vlookup(A2:A, E2:F, 2, false))
which will look up every name from first table (column A) in the column E, and return the matching value in column F. Result:
+---+-------+---+---+
| | A | B | C |
+---+-------+---+---+
| 2 | Jim | 3 | 7 |
| 3 | Sarah | 4 | 9 |
| 4 | Bob | 5 | 8 |
+---+-------+---+---+
In practice, one should filter out empty lookup values to improve performance:
=arrayformula(vlookup(filter(A2:A, len(A2:A)), E2:F, 2, false))
If the second table contains some names not present in the first, they will not be returned by the above formula. In this case it is better to prepare a full list of names, for example with
=sort(unique({Sheet1!A2:A; Sheet2!A2:A}))
which collects the names from A columns of two sheets, eliminating duplicates and sorting. Then look up those using vlookup as above.

Google Sheets - plot two sheets as line chart

I have two sheets in a google sheets document. They look something like this:
| Date | Value |
| 2015-01-01 | 100 |
| 2015-02-04 | 200 |
| Date | Value |
| 2015-01-01 | 100 |
| 2015-05-04 | 150 |
The dates and values are NOT regular. I'd like to plot both tables into a single line graph with date along the x axis, and two lines representing the values in each of the tables respectively. I don't want to have to merge the two tables, unless I can merge them automatically with a pivot table or something.
When I insert a chart, I have to choose the column which represents the x axis. In my case, I need the date column from both tables, so effectively two columns to represent my x axis.
A use case for this is simply showing the bank balances for two separate accounts in a line graph.
Thanks.
You can create another table on a new sheet that will merge the data columns from each of these tables, and then have two VlookUp columns, one for each table, and create a graph based on these three columns.
two merge Data columns from two different sheets use this
=FILTER({Sheet1!A:A;Sheet2!A2:A},{Sheet1!A:A;Sheet2!A2:A}<>"")
Your second column will will have the following VlookUp formula
=IFERROR(VLOOKUP(A1,Sheet1!A:B,2,false))
Third Column
=IFERROR(VLOOKUP(A1,Sheet2!A2:B,2,false))
Then just make a graph based on this table that should look something like this
| Date | Value |Value |
| 2015-01-01 | 100 | |
| 2015-02-04 | 200 | |
| 2015-01-01 | | 100 |
| 2015-05-04 | | 150 |

Resources