How to get specific label in the result on performing sum in PROMQL - promql

I'm trying to get count of distinct user logins per day. I'm able to get the list of user through group( logged_in_users{tenant="abc"}) by (user_id,login_date)
However unable to get the login_date as field in the output when I perform sum or count operation.
Below is a the tabular format of the o/p I'm trying to achieve

Related

Configuring Azure Log Alerts using two columns from a summarized table

I am trying to configure an alert in Azure that will send an email when a device has responded as "offline" 3 or more times in the last 15 minutes. The query I am using returns a summarized table with two columns, "Name" and "Count", where Count represents the number of offline responses.
Name
Count
ABC
4
DEF
3
My issue comes into play when trying to set up the conditions for the alert. Ideally I want to trigger an alert for any row where Count is greater than or equal to 3.
I can measure off of Table Rows or Count, but cannot seem to wrap my head around how to set up measurement and dimension splitting in a way that behaves similar to my goal I covered above. Thus far I have been able to set it up using Count, but it seems to only allow aggregating the values in Count, rather than looking at each row individually.
I have considered writing individual queries for each device that would return every offline response, and simply alerting off of the number of rows returned. I would much rather keep this contained to a single query. Thank you for any help you can provide.

I need to show the order ID and the order total for largest order (order ID-dollar amount)?

The Database. I need to find the order ID and the largest order in terms of dollars using SQL. I attached the OM database. Using SQL I think I would need to use group by or order by but I just need to find the largest order.
select order_id from orders
Union
sum(unit_price) from items;
It resulted in an error. I wanted it to show the order id and the sum of the unit_price and get the largest unit price to get the largest order. I’m getting an error message saying query without GROUP BY and nonaggregated column.

query does not include the specified expression 'ColB' as part of an aggregate function

I am using this query and it is working perfect but in excel as a database, it is giving me an error of aggregate function -
solution: once I add all column in the group by I don't get sum and Group by doesn't work.
select ColA,ColB,ColC,ColdD,SUM(ColE),ColF,ColG FROM automate GROUP BY ColA
One picture indicates table structure:
Another one is expected output:
Please help me if someone knows- MS-Access / excel as database
Every field in your SELECT part must be either GROUPed BY or aggregated. If all values are guaranteed to be the same or if you don't care which value will be picked use FIRST(), otherwise use the appropriate aggregate function (MIN, MAX, FIRST, LAST, SUM, etc.)
Example:
SELECT ColA, FIRST(ColB), FIRST(ColC), FIRST(ColdD), SUM(ColE), FIRST(ColF), FIRST(ColG) FROM automate GROUP BY ColA

Using groupsVariable in COLLECT to track unique values

I'm using the following AQL to track unique visitors by month and year. Each hit contains a datetime stamp, _date, and a user name, user.
FOR hit IN PageHits
COLLECT month = DATE_MONTH(hit._date),year=DATE_YEAR(hit._date) INTO user=hit.user
SORT year,month
RETURN {month,year,uniqueVisitors:LENGTH(UNIQUE(user))}
The query calculates the correct answer but it strikes me as inefficient because the variable user contains many duplicates. The final LENGTH/UNIQUE removes these and returns the number of unique visitors.
I looked at AGGREGATE but all of the operations are statistical.
So, is there any way to add only distinct/unique values into the group variable user?

Formula in Netsuite Saved Search

I have a problem here. In Column 1 I have count of All he transaction, In column 2 I have Count of transaction of specific status. In column 3 I want the percentage of above 2; like count of specific transaction/Count of total. Is it possible in Netsuite?
Actually there is an interesting feature that makes this possible. Formula fields that have aggregate functions work when the row has an aggregate on it. So for instance if you wanted to see a percentage of orders with status Billed on a Sales Order search you would enter a Formula (Percent) result with a formula like:
sum(case when {status} = 'Billed' then 1 else 0 end) / count({tranid})
and apply an aggregate to that column. The sample uses Maximum but Minimum and Average produce the same result.
I think that isn't possible by just saved search.
You will have to group on search result column status, so, all the count total will be based on statuses and you can't write aggregation based on other search results' columns.
you can further write a suitelet/portlet script to use the saved search result and calculate the stats before presenting on UI.

Resources