Count the number of columns in a column group - reporting-services

I need to report the average number of customer visits each engineer makes per month.
My SQL query creates a temporary table of months between the start date and end date and left joins this to the main data table, to ensure rows are returned even for months where no visits were made.
So an example of the data returned from SQL may be:
My report has two column groups, one for year and one for month, and I have a row group for the engineer.
For this report, the date is always returned as the first of the month, even though the actual visit could be on any date.
At the end of each year there is a cell which contains Count(Customer) and totals the number of visits the engineer made in that year. I would also like to have a cell which displays the average number of visits made each month in that year.
For a complete year I could simply divide by 12. However for a partial year I need to count the number of month columns for that year.
I tried CountDistinct(Month) but this only counts months where at least one visit was made, making the monthly average incorrect.
How can I get a count of the number of columns in a column group, including columns with no data?
Thanks.

The way I would do this would be to add a column into your temporary dates table that had the number of months selected in it.
You could do this by either counting the months in the temp table then appending the value to it or, if the dates table contains more than just months then work it out based on the parameters you pass in.
For example
SELECT *, DATEFIFF("m", #startDate, #endDate) as NoOfMonths
INTO #myTempDateTable
FROM myDateTable
WHERE etc...
Then in SSRS you can simply divide your total by this number.

Related

Calculate average session length per daily active user?

I'm pretty new to SQL and I'm struggling with one of the questions on my exercise. How would I calculate average session length per daily active user? The table shown is just a sample of what the extended table is. Imagine loads more rows.
I simply used this query to calculate the daily active users:
SELECT COUNT (DISTINCT user_id)
FROM table1
and welcome to StackOverflow!
now, your question:
How would I calculate average session length per daily active user?
you already have the session time, and using AVG function you will get a simple average for all
select AVG(session_length_seconds) avg from table_1
but you want per day... so you need to think as group by day, so how do you get the day? you have a activity_date as a Date entry, it's easy to extract day, month and year from it, for example
select
DAY(activity_date) day,
MONTH((activity_date) month,
YEAR(activity_date) year
from
table_1
will break down the date field in columns you can use...
now, back to your question, it states daily active user, but all you have is sessions, a user could have multiple sessions, so I have no idea, from the context you have shared, how you go about that, and make the avg for each session, makes no sense as data to retrieve, I'll just assume, and serves this answer just to get you started, that you want the avg per day only
knowing how to get the average, let's create a query that has it all together:
select
DAY(activity_date) day,
MONTH((activity_date) month,
YEAR(activity_date) year,
AVG(session_length_seconds) avg
from
table_1
group by
DAY(activity_date),
MONTH((activity_date),
YEAR(activity_date)
will output the average of session_length_seconds per day/month/year
the group by part, you need to have as many fields you have in the select but that do not do any calculation, like sum, count, etc... in our case avg does calculation, so we don't want to group by that value, but we do want to group by the other 3 values, so we have a 3 columns with day, month and year. You can also use concat to join day, month and year into just one string if you prefer...

how do i group customer entries using months across different years in ssrs reports in nav

I am trying to get Sum of each customer ledger entries and group the Ssrs report into months across different years. For instance, I should be able to filter with the year 011117..310318, this should give me entries of each customer grouped per month: November, December, Jan(18), Feb, Match.
You can do this by using a matrix in your report.
Add the matrix and set the row group to group by Customer (whatever makes the customer unique such as an ID).
Add column groups by month and then a parent column group by year. If you don't have separate columns for months and years in your dataset, you can use expression into the group expression such as..
=Month(Fields!myDateField.Value)
=Year(Fields!myDateField.Value)
In the data 'cell' just drag the value you want to aggregate there.
That should give you a basic working matrix.
If you need more help refer to the SSRS documentation on the matrix control.
https://learn.microsoft.com/en-us/sql/reporting-services/report-design/create-a-matrix-report-builder-and-ssrs?view=sql-server-ver15

Is it possible to limit RunningValue to look back for a certain number of rows?

Im trying to average the past 5 rows in my table i created in SSRS grouped by date(Monday of every week). Ive tried runningValue however it looks back at all the past rows for each group. Is there a way to limit the scope to just the past 5 rows or weeks for each Date group.
Thanks
I would accomplish this with grouping. I don't know what your dataset is like but I assume it is a SQL query you can modify. The easiest solution would be to add a week number column to your query. For example:
SELECT datepart(week, YOURDATE) as WeekNumber
More info on datepart:
https://learn.microsoft.com/en-us/sql/t-sql/functions/datepart-transact-sql?view=sql-server-2017
Once you have a week number, use the table creation wizard in Report Builder and add WeekNumber as a row group. This will group your values by week number and give you a total under each week. You can change the total by double clicking and making it AVG() instead of SUM().
Note: If you already have each 5 day period in a group, you should be able to right click that and add total. At which point you can just change the SUM to AVG there.

SSRS Sum values by week,month,and year

Report value of stock
I've created a stock value report.
The problem occurs with the addition of columns (month, year). I would like to set it to show the value of the last week in the month and year.
After reading your comment I think I know the best way for you to get there.
You want only the value of the last week within a Year/Month/Week column group. I would keep all the groups the way you have them setup with two small tweaks.
Drop the detail of the week group, keep the group, just no detail column group band.
Add a column group footer to the week group and simply apply the value as
=Last(Fields!WeekValue.Value)
That way you should have Year/Month and one column for weeks, the footer column and you simply pull across the last value from within that group.

Date is automatically resetting to beginning once it reaches the month end in SSRS

I have a matrix table which contains a day(currentdate value) as row group and month as a column group. The column group has two child columns one contains the data represents a value which falls on that particular day of that month and another is a running value. like wise the column values represents for current and previous month. Now the problem is for the month which doesn't have the date 31 contains the data which actually belongs to the particular months start date data. to understand how the data is populating for that particular row I added a column of date field. it shows the start date of the month.
I would like to know how to avoid this automatic data resetting.
Sample image of the issue