GroupBy Query over YRBSS Socrata API - socrata

Need help to build a sample query to get YRBSS 2015 statistics for questioncode H43 and grouped by race. I was following docs1 and doc2 and was able to get complete data for 2015 by following query:
https://chronicdata.cdc.gov/resource/6ay3-nik2.json?$where=(StratificationType='State' OR StratificationType='National')&year=2015&questioncode=H43
However $group=race is not working(is this possible? please advice). Any help would be much appreciated.
This question might not look technical but since support center suggests to post questions on stack overflow, I'm posting it here

What was your query using the $group=race? You will need to have a select statement and some aggregation function (e.g., count, sum, etc.).
Guessing that you want counts of individual responses by race, this statement will work:
https://chronicdata.cdc.gov/resource/6ay3-nik2.json?$select=race,count(race)&$where=(StratificationType=%27State%27%20OR%20StratificationType=%27National%27)&questioncode=H43&year=2015&$group=race
It's preceded by $select=race,count(race) to provide counts.

Related

Crack the expression

I am trying to understand expression in QV for the past few days and am unable to follow what it is trying to do especially the aggregate part with a nodistinct sum.
I've tried to understand how aggregate works and how nodistinct with sum but am not able to connect with the rest of the expression.
sum([INFLUENCE ON SALE]
* aggr(NODISTINCT SUM({<PART_NUMBER, [INFLUENCE ON SALE],[Campaign
Name],ROOTCAUSE=>}[TOTAL OCCATIONS 12]),KEY,YEAR)
/aggr(NODISTINCT SUM({<PART_NUMBER, [INFLUENCE ON SALE],[Campaign
Name],ROOTCAUSE=>}[TOTAL OCCATIONS 12]),YEAR))
WHAT is this expression trying to do with the aggregate and nodistinct part. can this be simplified and explained with a simple example?
you have to show the chart (table) in order to understand the use of nodistinct in this specific calculation. nodistinct "spreads" the results across dimensions even though the dimension is not in the aggr function...

Conditional Aggregate Lookup - SSRS

I have a report with two datasets to summarise the number and value of incomplete orders by status. I have a "Back Order" column, which is using the 'Lookup' function to refer to a second database, based on a whether the Fields!IsBackorder.Value returns true. This works at line level, but I've run into issues at the aggregate level.
For the total count of orders, this forumula works:
=SUM(IIF(LOOKUP(Fields!SalesOrderID.Value, Fields!SalesOrderID.Value, Fields!IsBackorder.Value, "DstBackorders") = "TRUE",1,0))
However, for the total value of orders ("Fields!NetValue.Value"), this returns '#Error'
=SUM(IIF(LOOKUP(Fields!SalesOrderID.Value, Fields!SalesOrderID.Value, Fields!IsBackorder.Value, "DstBackorders") = "TRUE",Fields!NetValue.Value,0))
I've tried custom aggregate functions but I haven't found any that work. I'm not sure how I'm getting this error.
Any suggestions would be really helpful.
Thanks,
Report Screenshot
The syntax looks perfectly fine , also the lookup looks good , can you please check on the below things in your DataSet:
Is Fields!NetValue.Value in scope of the current DataSet.
Are we using the correct data type for Fields!NetValue.Value(Something which is aggregatable , like int , decimal etc.)

SQL SUM condition on each column

I'm giving my best efforts to write a query to get the desired output format shown the second table here. Is there a better way to achieve this, table 1 has the raw data and I want to find the sum of monthly usage of unique devices for a given user. Any help is really appreciated.
table format
Apologize for not being clear in first place. tagged different image to illustrate better. If you look at this data in new image attached. After I filter by username - I get that data output. My need is to get the sum of usage by month by device.
Ex: rows highlighted in the image, where iPhone-6sPlus is used multiple times each month across months. I'm looking for a query that gives output as
iPhone-6SPlus is used xx_hrs in Jan, yy_hrs in feb so on. Similarly for other device models. Hope this helps. Thanks.
Better image
create table #product (model varchar(50),users varchar(5), monthofuse Varchar(3),yearofuse int,usage int)
Insert into #product values('X','a', 'JAN',2010,34), ('X','a', 'Feb',2010,20),('X','a', 'Mar',2010,10),('Y','a', 'Jan',2010,30),
('Y','b', 'Jan',2010,30),('Y','b', 'Feb',2010,30),('X','a', 'JAN',2011,50)
select * from #product
Select * FROM
(Select users,monthofuse,usage,model from #product) q
Pivot
(
sum(usage) for q.monthofuse in([JAN],[FEB],[MAR],[APR],[MAY],[JUN],[JUL],[AUG],[SEP],[OCT],[NOV],[DEC]))As pvttable

Querying https://musicbrainz.org for all artists

How can I query for all artists who were born after 1720 and died before 1900 on https://musicbrainz.org?
I need to retrieve their IDs and some information about them.
Is it possible to get data in JSON format?
for those who dont want to read a long post, here is everything the OP asked for in only one query:
http://musicbrainz.org/ws/2/artist/?query=begin:[1720 TO 1900] AND end:[1720 TO 1900] AND type:"person"&fmt=json
This should return perfect results, and has got to be the best answer possible.
- all artists, born after 1720 and dead before 1900, in json format, which retrieves their IDs, and lots of information about them...
The explanation and thought process:
Since Brian's currently accepted answer includes a link to the API document, i can say it is technically complete but I don't consider pointing to the spec a the best possible answer, and can be greatly improved.
Firstly it is easy to return json by adding the json format parameter.
&fmt=json
Secondly while i don't reckon there where many boy bands back in the day, given that OP is asking about births and deaths we may conclude they are interested in only people rather than groups other types of artists.
AND type:"person"
At which point as Brian suggests another call for each end date and then filter the results taking only those who died by 1900.
If you did this you would need to do way more than 180 searches the best answer suggests, but rather one for each birth and each death year combination, so technically 1720 to 1720, all the way through 1900-1900, my math stinks but that is thousands of searches.
But what makes this still such a horrible search is because sometimes dates are either written with only the year, and then sometimes written with month date and year, so for example if you search for begin 1929 and end 1900
So if a date is written to include not only year but month/date you would not get any results for this artist because of the full birthday:
ex:
id "2b8a16a9-468f-49b0-93ea-5e6726f41643" type "Person" life-span
begin "1929-11-10"
end "1990"
ended true
Therefore in order to get any good results using only the year you would need to add the fuzzy search syntax
musicbrainz.org/ws/2/artist/?query=begin:1960~ AND end:1990~ AND
type:"person"&fmt=json
But this does nothing to solve big problem of the magnitude of searches suggested, so knowing its LUCENS based I decided to learn some LUCENS, and realize there is range syntax:
Therefor you can do all of the above with one query:
http://musicbrainz.org/ws/2/artist/?query=begin:[1720 TO 1900] AND
end:[1720 TO 1900] AND type:"person"&fmt=json
PS I recommend to start adding quotes or even url encoding your parameter values to prevent breakage.
For example leaving quotes off begin and end numerals in the example above has no problem but off the type value will fail.
First, Musicbrainz only returns XML, as far as I know, so you'll have to convert the results to JSON.
To answer your question, it doesn't look like you'll be able to get the data you want in a single call. (The following is based off the XML Web Service Search documentation.)
This call will retrieve all artists who were born in a given year:
http://musicbrainz.org/ws/2/artist/?query=begin:1720
I believe you'd need to write 180 calls (one for each year between 1720 and 1900) to get the data you need. You'd also need to manually filter out artists who died after 1900, by looking at the <end> node within <life-span>. This is because the end field will only get you artists who died in a specific year.

sum 2 columns in a reporting services matrix

I have matrix in my report having column field "Layer Origin".
Layer Origin has 3 values:
New Business
Renewal - Rewritten
Renewal - Same Terms
if i run the report as is it will show Totals for each of the 3 above.
What i what is to show the Totals for:
New Business
Renewal (Renewal - Rewritten + Renewal - Same Terms)
i.e.: i want to sum the values of Renewal-Rewritten and Renewal- Same Terms
Below is a screen shot to illustrate my request.
Thanks for your reply.
ive tried the below code but it gave me error (see the below screen)
=SUM(IIF(Fields!Layer_Origin.Value="New Business",0,Fields!USD_Cedent_Premium.Value))
I appreciate your feedback.
This situation can be handle if you just use conditional SUM in Total Column
=SUM(IIF(Fields!Layer_Origin.Value="New Business",0,Fields!USD_CED.Value))
Instead of using
=SUM(Fields!USD_CED.Value)
I think it will solve your problem. Pardon me if some spell mistake or syntax error. As i dont have any VS intalled to check.
Share if you still face any issue bcz this one is definetly i can help.
After Several testing i found the problem.
the code should be as below:
=SUM(IIF(Fields!Layer_Origin.Value="New Business",CDec(0.00),Fields!USD_Cedent_Premium.Value))
Thanks for your assistance