SSRS Report Expression to display Weekly, Monthly and YTD totals - ssrs-2012

Have a report that displays daily counts and dollars. I'm trying to additional columns to display weekly, month to date and year to date totals.
In the past I've done this by creating separate weekly, monthly and ytd data sets and then used lookup expressions to populate the fields. Is it possible to use expressions that reference my primary data set, which includes a date column, to get weekly, mthly and ytd totals?
If this is possible, I'm not sure how to write the expressions to:
look back at the past 7 days and get totals for those days
Get totals for the current month
Get YTD totals.
Any help that anyone can provide would be appreciated. I've attached an example of the report I'm trying to create.
Thank you.

You would just need to use an expression for each as a filter your Dollar Amt column. It will determine whether to add the dollar amt or a 0 for each row of data.
I assume that you have a date field - I'll call it DATE.
YTD
=SUM(IIF(YEAR(FIELDS!DATE.VALUE) = TODAY.Year, FIELDS!DOLLAR_AMT.VALUE, CDEC(0)))
Monthly
=SUM(IIF(FORMAT(FIELDS!DATE.VALUE, "yyyyMM") = FORMAT(TODAY, "yyyyMM"), FIELDS!DOLLAR_AMT.VALUE, CDEC(0)))
The weekly would be a little different and depend on your week (sun - sat, mon - sun...) and your first day of the week setting but you get the general idea. If your using Monday - Sunday maybe something like:
WTD
=SUM(IIF(FIELDS!DATE.VALUE >= TODAY.AddDays(1 - TODAY.DayOfWeek), FIELDS!DOLLAR_AMT.VALUE, CDEC(0)))
The CDEC is used to add the 0 to the dollar amounts - otherwise you'll get an error when it tries to add 1.25 + 0. It's to Convert to DECimal.
The same logic will work for the counts - just use the Unit_Count field and remove the CDEC conversion for the zeroes.

Related

DAX - Month Name column error when dropped in value field

I have a simple date table (marked as a Date Table)
the Date column is native to it, the rest are calculated columns.
This issue will be about these of them:
Month Name = FORMAT(Dates[Date], "Mmmm")
Month = Month(Dates[Date])
Both set to "Don't summarize".
I dropped them into value field of a visual out of curiousity, and a curious thing happened - despite "don't summarize" they took MIN form of value to display, but Month Name came out incorrect.
Image 1: 3 out of 4 lines in the column First Month Name are wrong, unlike Month which is fine.
Image 2: added Date to the row fields to check - line by line it's fine, but subtotal still wrong:
Image 3: I filtered Month Name in data view for February, to see which lines are for Month value of 1 - there is none.
This is a blank new report, no measures, no filters - that's all it is.
If someone can explain why this happens, thanks in advance
The columns with "Earliest"/"First"/"Min" are summarizing because they are implicit measures in a matrix visual. Since there are multiple months in one quarter it has to aggregate somehow.
The month name is a text field, so it sorts alphabetically by default. If you want it to sort by month number instead, you can use the Sort by Column feature to sort Month Name by Month.

QlikView add Calculated Dimension within a Table

Hi Guys I am trying to create a table in Qlikview that shows me sales starting from current week (Week 11) and works back Week 10 Week 9 etc to week 52 previous year. I can do this by creating individual expressions but this would be extremely time consuming. I have been trying to write an expression but having no joy. Is there a way i can create these columns within the table using calculated dimension where i can write a formula, something like:
= sum({=$(=Week(today()-52))<=$(=Week(today()))"}>} QTY)
That would create each week and show the qty of sales.
I would use a numeric representation in the script:
create a field in your calendar: year(date)+Num(Week(MyDate), '00') as yearweek
then you can create a variable vStartWeek: =(max(Year)-1)&52
then your expression will be = sum({<yearweek={">=$(vStartWeek)"}>} QTY)
no need for <=Week(today()) unless you already sold something in the future ;D

Can I generate the number of business days in a month in Visual Studio?

I have a report that takes sales data from a few tables. I want to add a field that will divide the total sales for the given month by the total number of business days in that same month. Is there a way I can calculate that in an expression? Do I need to create a new table in the database specifically for months and their number of business days? How should I go about this?
Thank you
Intuitively, I would say that you need a simple function and a table.
The table is to host the exceptions like Independence day, labor day, etc.
The function will get two parameters: Month and Year (I'm not providing any sample code since you haven't specified which language you are using).
It will then build a date as yyyy-mm-01 (meaning, first day of the month). If will then loop from 2 to 31 and:
Create a new date by adding the index of the loop to the initial date,
Check if the resulting date is still within the month,
Check if it is a working or not working day (e.g. Sunday),
Check if it is found within the table of exceptions.
If the created date passes all the above tests, you add 1 to the counter.
Though it might look complex, it is not and it will provide you the correct answer regardless of the month (e.g. Feb.) and the year (leap or not).

DAX - Sum Workdays By Month within Range

I've been at this one a while.
Objective: Pivot a monthly summary of days worked by Resource within the range for that Resource line where those dates (from StartDate to EndDate) correspond to the Dates table IsWorkday field.
Thanks for your help!
It depends on how you define what a workday is. I suspect this is Monday thru Friday? If so, try the weekday function.
=WEEKDAY(serial_number,2)
Where serial_number is the cell with a date you want to identify. This would not exclude holidays, I would recommend an index/match on some holiday reference table for that.
https://support.office.com/en-us/article/WEEKDAY-function-60e44483-2ed1-439f-8bd0-e404c190949a

Visual Studio Report Designer: I don't understand group filters

I'm writing a report that has proposal information by estimator per month. So I created a matrix where each row is grouped by estimator and each column is grouped by the month.
The thing is, my query includes data for this year AND last year, but the columns by month should only contain this year's information. So I though simple, I'll create a filter: Year(variable_date) = Year(Today()).
When I do this, no record information shows up. But then I changed the column to group by month AND year and suddenly, it works. Only 2015 records show up in the calculations per month.
Why did I need to group it by month AND year? Why couldn't I just group by month and have the filter remove records that didn't have the correct year using the filter group property tab?
Thanks!
P.S. I hope I have the tags right...
It sounds like month and year are separate fields. So when you group only by month it is grouping all of the rows where the value for that field is the same. (Month=8 exists in 2014 and 2015.) The values are just numbers to SSRS and it doesn't know it needs to look at the year field too unless you tell it to.

Resources