SQL Server Reporting - sql-server

I have a Matrix style report that I have created and it is currently displaying a total count of items for a series of companies throughout a 12 month period.
[Company1] [Company2] [Etc....] [Total]
[May] (Count)(Percent)
[June]
[Etc]
[Totals]-----------------------------------------------------
The last column total is a subtotal function and automatically adds column counts based on what is in the Column group which in my case gives me a total for both (Count)(Percent)
I only want to show <Count> but I don't find any method of modifying the parameters for the subtotal function.
The only way I found was to add an additional matrix to the right hand side of the main but only display total counts. Kind of hokey and I will refrain from implementing it at this time.
Any suggestions?

Related

Qlikview Pivot Table Top X by week

I have a pivot table with week number (columns) versus product (rows). I want to see the top 10 products, based on sales, per week, a value of 1 would indicate the product is in the top 10. I'm using the expression below and I'm getting the Top 10 sales over all weeks. How do I get a weekly top 10 (each column would have ten values)?
=if(Aggr(Rank(sum([SALES])),PRODUCT)< 11,1,0)
I would say you are almost there, but you need to add another parameter to the Aggr function (like you've said you want the rank by Product and Week, and currently you are only taking Product into account).
Without knowing the details of your model, the expression would be something like :
=if(Aggr(Rank(sum([SALES])),PRODUCT,WEEK)< 11,1,0)

SQL syntax to calculate total menu items per meal orderID across multiple meal orderIDs

I am new to SQL and Stack overflow and have a question about SQL Server syntax. i have searched online but I am not finding what I need and I would appreciate your assistance in this matter.
I have data in a source table for meal orders (each with a specific ID (e.g. 12345C) and items of each order (e.g. sandwich, drink, chips), each with an associated number starting with 1. For instance, the sandwich would have an item number of 1, the chips would be item # 2, and the drink would be item # 3 for the same orderID 12345C. The prior example would therefore have 3 rows of data in the source table for orderID 12345C.
My questions are these:
how do I use a SQL expression to determine the number of items per each order (e.g. 3 for the above example, which is also the maximum value for item number for each orderID)
and then add all of these items per order across hundreds of orders per day to determine the daily total number of items ordered.
So, if I had 3 orders in one day - one with 2 items, the second with 3 items, and the third with 4 items, I would like my final number to be 9.
This number is for use in a Sisense dashboard that allows SQL syntax in the field definition. Thank you for your help!
It is a bit difficult to explain but I am not able to use a query from a table because I am working with a dashboard in Sisense so I am adding fields in a pivot display and one of the fields I would like to include is the total count of order items per day (across several dozen orderIDs).
Here is an example of the data in the table: from the example I would like the final answer for orderID 1787588 to be 3 (there are 3 items within the order).

Google Data Studio date aggregation - average number of daily users over time

This should be simple so I think I am missing it. I have a simple line chart that shows Users per day over 28 days (X axis is date, Y axis is number of users). I am using hard-coded 28 days here just to get it to work.
I want to add a scorecard for average daily users over the 28 day time frame. I tried to use a calculated field AVG(Users) but this shows an error for re-aggregating an aggregated value. Then I tried Users/28, but the result oddly is the value of Users for today. The division seems to be completely ignored.
What is the best way to show average number of daily users over a time frame? Average daily users over 10 days, 20 day, etc.
Try to create a new metric that counts the dates eg
Count of Date = COUNT(Date) or
Count of Date = COUNT_DISTINCT(Date) in case you have duplicated dates
Then create another metric for average users
Users AVG = (Users / Count of Date)
The average depends on the timeframe you have selected. If you are selecting the last 28 days the average is for those 28 days (dates), if you filter 20 days the average is for those 20 days etc.
Hope that helps.
I have been able to do this in an extremely crude and ugly manner using Google Sheets as a means to do the calculation and serve as a data source for Data studio.
This may be useful for other people trying to do the same thing. This assumes you know how to work with GA data in Sheets and are starting with a Report Configuration. There must be a better way.
Example for Average Number of Daily Users over the last 7 days:
Edit the Report Configuration fields:
Report Name: create one report per day, in this case 7 reports. Name them (for example) Users-1 through Users-7. These are your Row 2 values. You'll have 7 columns, with the first report name in column B.
Start Date and End Date: use TODAY()-X where X is the number of days previous to define the start and end dates for each report. Each report will contain the user count for one day. Report Users-1 will use TODAY()-1 for start and end, etc.
Metrics: enter the metrics e.g. ga:users and ga:new users
Create the reports
Use 'Run reports' to have the result sheets created and populated.
Create a sheet for an interim data set you will use as the basis for the average calculation. The first column is date, the remaining columns are for the metrics, in this case Users and New Users.
Populate the interim data set with the dates and values. You will reference the Report Configuration to get the dates, and you will pull the metrics from each of the individual reports. At this stage you have a sheet with date in first columns and values in subsequent columns with a row for each day's values. Be sure to use a header.
Finally, create a sheet that averages the values in the interim data set. This sheet will have a column for each metric, with one value per column. The one value is calculated from the series in the interim data set, for example =AVG(interim_sheet_reference:range) or any other calculation you'd like to do.
At last, you can use Data Studio to connect to this data source and use the values. For counts of users such as this example, you would use Sum as the aggregation field type when you are creating the data source.
It's super ugly but it works.

Group by array or shared value

My invoice report pull due dates depending on the selection of Payment Plan Code on UI (either semi, monthly, quarterly, annually, or even 18 installments.) It also accordingly pulls gross premium per due date. I need to pull this table per due date and the sum of the gross premium if they fall into one due date.
What I do is break and save the due dates into array. How can I group by them? Crystal doesn't seem to allow me to group by a shared value, or group by array.
You don't need array for this purpose.. using array complicates the report instead you can manipulate grouping like below:
Create a formula like below and use this formula to group.
if parameterselection = "monthly"
then Month(duedate)
else if parameterselection = "yearly"
then Year(duedate)
.
.
.
.
formula till end
Edit-------------------------------------------
In this case as per your comment you need to create one more group (Group2) with due date.
Now you have two groups group 1 is the one I wrote first and group2 using due date and this works

SSRS Count Rows of Previous Group (Table in Matrix)

Using the sample below, I am looking for a way how to count the number of rows in the table in the previous group. My report is setup using a Matrix and a table ("Tablix3") in the data region of the matrix.
The column groupings are called "DayOfTheWeek" and "AMPM".
In the area with the blue box around it, I need the PM group to count the number of rows in "Tablix3" for the AM group on that day, which is 2. When the value is greater than 1 I will use expressions to alter the background colour accordingly as the bottom right pink background shouldn't be there.
I am using SSRS 2008.
Unfortunately, no. You have to do it in the query.

Resources