I have cloudwatch entries that may be group with respect to a certain field. To be clear assume that field is city. I would like to count the entries with respect to cities. This is the easy part.
fields city
|stats count(*) by city
However I also want to get maximum minimum and average of this count, but I can not. Is it possible to have such queries i.e:
fields city
|stats avg(count(*) by city)
The console return an error for such query : mismatched input 'by' expecting {SYM_COMMA, SYM_RParen}
Here's how you'd do it: You'd first get the count (that you already figured) and then get the metrics you want by calling the relevant functions like so:
fields city
|stats count(*) as cityCount, avg(cityCount), max(cityCount), min(cityCount)
Related
This question is a follow up to another SO question
I want a bar chart to show the amount of orders in a given date or range. Koen's updated answer shows:
'The "Value" is the amount of orders on each day. Update your source query to include a count of the orders and group by day. Then make your value attribute the column that has the count.'
How would I go about doing this?
Summary: I have a table ORDERS which contains column ORDER_DATE. I have created a Chart as a Bar type. I want the chart to show the amount of orders in a given date or range.
I'm following this Youtube tutorial which shows how to create a datepicker that returns a range in a Report. I'm trying to replicate this in a chart.
What I've done so far
Created datepicker items P5_DATE_FROM and P5_DATE_TO
Changed the Series Source Type to SQL Query
select ORDER_ID,
ORDER_NUMBER,
ORDER_DATE,
STORE_ID,
FULL_NAME,
EMAIL,
CITY,
STATE,
ZIP_CODE,
CREDIT_CARD,
ORDER_ITEMS,
APEX$SYNC_STEP_STATIC_ID,
APEX$ROW_SYNC_TIMESTAMP
from ORDERS_LOCAL
where ORDER_DATE between TO_DATE(:P5_DATE_FROM,'YYYY-MM-DD') and TO_DATE(:P5_DATE_TO,'YYYY-MM-DD')
Source Page Items to Submit added P5_DATE_FROM,P5_DATE_TO
I basically followed the exact steps of the video.
However, on the Page Designer I cannot save and run page until I select Column Mapping - Label and Value. I've set the Label as ORDER_DATE but I am unsure of what to select for the Value.
Setting the Value to ORDER_DATE shows an error Ajax call returned server error ORA-01403: no data found for CHART Count Orders by Date.
and selecting any other Value such as ORDER_NUMBER or ZIP_CODE populates the chart with the actual integer value of the column (ex: ZIP_CODE returns a chart of x-axis: date, y-axis: actual zip code numbers)
-----------UPDATE----------
Per Koen's answer, I've updated the Source SQL Query to below but I am now receiving an error.
And if I copy the exact query that Koen suggested, I run into below:
I did some messing around and found if I include APEX$SYNC_STEP_STATIC_ID and APEX$ROW_SYNC_TIMESTAMP the missing expression error goes away but instead I receive the GROUP BY error.
Something like this (untested) should work. Use TRUNC to ensure all orders on the same date are grouped (since date has a time portion, you'd have a different column for each different date time. Use ORDER_DATE as label and ORDER_COUNT as value.
select COUNT(ORDER_ID) AS ORDER_COUNT,
TRUNC(ORDER_DATE) AS ORDER_DATE,
from ORDERS_LOCAL
where ORDER_DATE between TO_DATE(:P5_DATE_FROM,'YYYY-MM-DD') and TO_DATE(:P5_DATE_TO,'YYYY-MM-DD')
GROUP BY TRUNC(ORDER_DATE)
I need to change the inventory category for a couple of account numbers and only for a couple of companies. The inventory category for these accounts are mapped based on the account number but need to be changed specifically just for two companies. I've tried to filter by the company number and then find/replace, which worked fine, but then I can't unfilter to bring back the rest of the companies. I can't change the category for just those account numbers because it is only different for just those two companies.
Lisa, Here's perhaps a simpler approach than where your current way is taking you.
If I begin with this table:
Then I add a column (Add Column -> Custom Column) with the following:
The formula uses an if statement to determine whether each row has a specific Account (Acct. 4) AND Company (Co. 8). If so, then 99 is returned as a new category value for that row of the new column. If not, then the original Inventory Category is returned as a value for that row of the new column. (Obviously, you would edit this formula accordingly, to support your account, company, and new inventory category values.)
Here's the result:
Then I could delete the original Inventory Category column and rename the remaining New Inventory Category column to Inventory Category.
IR based on PL/SQL Function Body returning SQL Query.
How do i can create Interactive reports based on multiple table and Deferent column name.
Exp :-
Select list item return three value
1 or 2 or 3
And the function return query basen on select list value
when Value equal 1
Select name, satate, country_id from cities
when value equal 2 Return
Select country, id from country
when value equal 3 Return
Select ocean,oc_id,from oceans
The three query return different column name and value.
Ok firstly, your question is poorly written. But from what I gather, you want an SQL query that returns different things based on an input.
I dont think you even need a plsql function body for this.
Simply do something like this:
SELECT * FROM
(SELECT name as name,
state as state,
country_id as id,
1 as value
FROM cities
UNION ALL
SELECT country as name,
NULL as state,
id as id,
2 as value
FROM country
UNION ALL
SELECT ocean as name,
NULL as state,
oc_id as id,
3 as value
FROM oceans)
WHERE value = :input_parameter_value;
Because if you are trying to display a variable number of columns and constantly changing their names and such. You are gonna have a bad time, it can be done, as can everything. But afaik its not exactly simple
No objections to what #TineO has said in their answer, I'd probably do it that way.
Though, yet another option: if your Apex version allows it, you can create three Interactive Report regions on the same page, each selecting values from its own table, keeping its own column labels.
Then create a server condition for each region; its type would be Function that returns a Boolean and look like
return :P1_LIST_ITEM = 1;
for the 1st region; = 2 for the 2nd and = 3 for the 3rd.
When you run the page, nothing would be displayed as P1_LIST_ITEM has no value. Once you set it, one of conditions would be met and appropriate region would be displayed.
I picked an entire table as a Data Source and picked my fields. The SQL of it returns as:
SELECT customer_id AS customer_id,
country AS country,
count(invoice_num) AS total_invoices
FROM sales
GROUP BY customer_id,
country
ORDER BY total_invoices DESC
LIMIT 10000;
I do not want this ORDER BY total_invoices DESC as it is ruining the entire result. What should I do?
I think it always orders by the first metric. If you have multiple metrics, you can re-order them to change which one is used in the Order By clause.
Under Customization, the bar chart also has a "Sort Bars" option to sort the x-axis by label, which might work for you depending on what kind of result you're looking for.
I have a flowfield that sums up a decimal value, but I need to limit the value in a report based on a date field that will be supplied as a parameter in a
report. How best do I achieve this?
a shortened version the CALC formula in the field definition looks like this:
Sum("MyTable".Unit WHERE (Institution=FIELD(No)))
When the report is run, there is a filter on MyTable based on a date field.
Does this field evaluate to the total sum of all the records, or just the filtered values?
No. Just filter on any field doesn't applies to flow fields.
You must use flowfilter to achieve this.
Your code should look like this:
MytableVar.reset;
MytableVar.setrange("Date Filter", 0D, TODAY);
MytableVar.calcfields(Unit);
where Date Filter is a field in the My Table with type flowfilter.
If My Table is used as Source Table it will work in tha same way. Just apply filter to Date Filter field.
For further reference see Inventory filed in the Item table.