Similar to Superset Computing 90th percentile response time, except with a SQL Server data source. SQL Server has a different syntax for its percentile functions where the variable is not specified in the main function call and I can't figure out how to input it as a Superset metric.
I have Type as a Dimension in my Superset chart. I put AVG([Time]) as a metric, I get that value for each Type row. Great. Now to do 90th percentile.
For 90th percentile, I try
PERCENTILE_CONT(0.9) WITHIN GROUP (ORDER BY [Time]) OVER (PARTITION BY [Type])
That errors with
"Column 'dbo.vw_Fire_Dashboard.Time' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
I've tried removing the OVER ... at the end as I did to adapt other metrics to Superset, but then it complains that
'PERCENTILE_CONT' must have an OVER clause.
Related
I want alert when i am fetching two different item in the oracle query
basically i want to check what ever i am searching it should from one policy when every i any getting two different policy i should get alert or some remark in another query that more then one item got fetch
for example
when i am fetching the data from oracle using the query i want the single item in the column and if i get multiple item i should get the alert
select * from table policy_id in ('100')
By asking, "when do I get 2 different items", or "when I have two distinct values" for a given key, you must aggregate rows in order to compute an aggregate value. COUNT, SUM, MIN, MAX, AVG, STDDEV, etc... are all aggregate functions that operate on multiple rows. But for them to operate on multiple rows, you must raise the granularity of your data to a higher level, or what we call "group by". Group by the key column(s) and aggregate across your fact columns to summarize those facts within those groups.
In your case, group by the columns for which you want to see unique values in separate rows. Then count how many rows were included in each group by using the COUNT(*) function. You may then wrap the output of that in a CASE or DECODE to conditionally test that output and return something different based on that output. In my example, test for 1, otherwise if more than one, you have multiple rows sharing the same key values. DECODE arguments are (test value, comparison value, result-if-true, result-if-false). So below will show "multiple policies" if there are 2 or more rows with the same policy,claim, req values, and NULL/empty if there are not.
SELECT policy,claim,req,DECODE(COUNT(*),1,NULL,'multiple policies') alert
FROM table
WHERE policyid = 100
GROUP BY policy,claim,req
I've got a Solr instance containing variable product prices that powers a site search. To search around a date and show results even if the exact requested date is not available, we use a query like this:
product_id: 759 AND arrival_date:[2016-05-20T00:00:00Z-3DAYS TO 2016-05-20T00:00:00Z+3DAYS]
The results are grouped by product_id. The grouping inherits a price asc sorting order from the main query.
This, unfortunately, has the negative side effect of always returning documents with the lowest price, regardless of the date, even if the requested date is available.
How can I sort within a group by proximity to a date?
Use the group.sort=arrival_date desc
Alternatively if you want to sort all results based on the date first then the price us &sort=date desc,price asc
I'm fairly new to SQL and I have been issued my first report to build. I have written an SQL query to give me a set of results that I would like to publish in a report.
I have unioned about 20 small queries all containing the correct amount of columns. One column is a misc column with about 15 different descriptions in (this is what I want to count).
I have uploaded my data set and now want to be able to choose a cell in my report to bring back a certain description.
At the minute I'm using
=count(fields!misc.values)
and it's giving me the whole count, about 200.
I would like to know if there is any kind of "where clause" (filter) which I can use to state which description results I want to bring back.
You can use am expression to count the misc.value you need. It will work like a count using a where clause:
=Sum(iif(Fields!misc.Value ="Some description",1,0))
Example:
For count the FSMethod with MethodOne as value I used this expression:
=Sum(iif(Fields!FSMethod.Value ="MethodOne",1,0))
Note the expression sums by 1 if the FSMethod.Value is MethodOne.
For count the rows with FSMethod column with MethodTwo value.
=Sum(iif(Fields!FSMethod.Value ="MethodTwo",1,0))
Let me know if this can help you.
Here's an MDX query which runs against Adventureworks.
SELECT NON EMPTY {[Measures].[Internet Order Count], [Measures].[Average Unit Price]} ON COLUMNS,
NON EMPTY([Product].[Status].[Status] ,[Customer].[Country].[Country]) ON ROWS
FROM [Adventure Works]
WHERE {[Customer].[Education].&[Bachelors],[Customer].[Education].&[High School]}
The interesting thing here is the where clause.
If I execute this and get a CellSet back, it contains different metadata depending on the Where clause.
If the where clause has a single element (take out high school, leave in bachelors for example) You end up with a slicer.
If you run it as above you don't. And worse, I can't find anywhere in the cellset which indicates a where clause was applied.
Does anyone have any idea?
I'm actually working on a SSAS Cube using SQL Server Reporting Services.
In order to filter a field, I need to use a calculated member which specifically use a parameter.
Here is my calculated member:
WITH MEMBER [Measures].[Comparable Stock Room] AS Iif (
[Stock room].[Stock room code].currentMember IS (Iif (STRTOMEMBER(#StockRoomCode).Count = 1, STRTOMEMBER(#StockRoomCode), xxx)),
0,
[Measures].[Retail sales amount invoiced including tax]
)
This works well if #StockRoomCode only have one value. But I don't know how to make it works when the parameter has multiple values. How to replace the 'xxx' ?
Can you help me or tell me how to do it a better way, thanks !
You could create a calculated member aggregating the members you want to report on and define the measure in tems of the calculated member, something like:
with member [Stock Room].[Stock room code].[foo] as
aggregate (strtoset (#StockRoomCode)),
member [Measures].[Comparable Stock Room] as
([Stock Room].[Stock room code].[foo],
[Measures].[Retail sales amount including tax])
(Note: not tested, just off the top of my head). Or,
with set [foo] as strtoset (#StockRoomCode),
member [Measures].[Comparable Stock Room] as
sum ([foo], [Measures].[Retail sales amount including tax])
select [Measures].[Comparable Stock Room] on columns,
(Slicing dimension such as time) on rows
from [cube]
where [other slice]
Note, with either, get your set expression right and test that first.