SSRS Reporting Services calculating 2 sums if parameter is true - sql

I have a simple income and covers served per day report, I need to calculate the variance % difference between this years income and last years income, but excluding any sites that opened this year.
I have the following expression however the results it returns are way out from what I am expecting:
=sum(iif(Fields!New_Site.Value=False And Fields!netSalesLY.Value<>0,CDbl(Fields!netSalesTY.Value/Fields!netSalesLY.Value),CDbl(0)))
New_Site is a Boolean parameter to filter out new/old sites, and both netsalesTY and netsalesLY are integer values.
Any ideas?
Thanks

The first thing I notice is that you're not referencing the New_Site parameter, you're referencing the New_Site field in your formula. If you wanted to reference the New_Site parameter, you would do it as
Parameters!New_Site.value
Not sure which you are really wanting to use.
Also, I may be misunderstanding what number you're trying to calculate, but if I understand you correctly, you're using the wrong formula. You're not using the percent difference formula, which will return the percent of this years sales related to last years sales, not a difference between the two. If what you want to know is the percent difference between the two years, it would be calculated as:
(Fields!netSalesTY.Value - Fields!netSalesLY.Value) / Fields!netSalesLY.Value
So if last year your netSales were $100,000 and this year they are $85,000, your current formula would return 85%, whereas the formula I just mentioned would return -15%, thus showing the decline in sales. So with the formula I gave you, a negative number would represent a decrease from last year to this year and a positive number would represent an increase from last year to this year.
Hope this helps!

Related

Writing a where clause query

I'm trying to create a query that will show the properties that were sold and were on the market for less than 6 weeks. In the listings table, there is BeginListDate and EndList Date.
So far my WHERE statement looks like
WHERE SaleStatus.Salestatus = 'Sold' AND DATEDIFF(YEAR,BeginListDate, EndListDate) >42
but that query is incorrect. I'm just confused on how to write a where statement where it only considers those that were on the market for less than 6 weeks.
Just to elaborate on #JamieD77's very correct comment...
Your condition:
DATEDIFF(YEAR,BeginListDate, EndListDate) >42
Says "The number of Years between the BeginListDate and the EndListDate is greater than 42". That's a hell of a long list period. You say you are looking for the the list period to be less than 42 days, so #JamieD77's suggestion to:
Datediff(day,BeginListDate, EndListDate) < 42
Is the right way to go. This says "The number of Days between beginlistdate and endlistdate is less than 42."
The difference here is the DatePart as #squillman suggested changing from Year to Day as well as the inequality itself. You wanted Less Than, <.
Hint but depended on how would you preferred in report or project.
this example and if both startdate and endate are in the same calendar week, the return value for week would be 0.
select DATEDIFF(week,getdate(),getdate()+7)
it has been consider week start for sunday based on system.

Referencing a measure in DAX DATESBTWEEN function

In Powerpivot 2013 I am trying to calculate unit sales per day between the last time an item was received and the last time it was sold, but I keep getting tripped up by the DATESBETWEEN fuction.
These measures return the dates of of the last recieve and last sale:
Lastsale:=CALCULATE(LASTDATE(InvDetail[Date]), InvDetail[Type]="Sale")
Lastrecv:=CALCULATE(LASTDATE(InvDetail[Date]), InvDetail[Type]="Receive", all(InvDetail[Date]))
This is what I'm using to get the units sold between the last receive and last sale, but it's not working. I don't get an error, just crazy big numbers.
UnitsSold:=calculate(sum(InvDetail[units]), InvDetail[Type]="Sale", DATESBETWEEN(InvDetail[Date], [Lastrecv], [Lastsale]))
If I hard-code in the dates as below, it works.
UnitsSold:=calculate(sum(InvDetail[units]), InvDetail[Type]="Sale", DATESBETWEEN(InvDetail[Date], date(2015,1,1), date(2015,2,1)))
I also have to get the number of dates in that date range too, but I haven't gone there yet.
Is there some reason why I can't use the measures in the DATESBETWEEN function?
It's tricky without the data but my guess is that inside the DATESBETWEEN() you just aren't getting the expected filter context.
The first thing I would try is incorporating the measures in a CALCULATE() with a FILTER():
= CALCULATE(SUM(InvDetail[units]),
InvDetail[Type]="Sale",
FILTER(ALL(InvDetail[Date]),
InvDetail[Date] >= [Lastrecv] &&
InvDetail[Date] <= [Lastsale]
)
)
You could adapt this to count your dates with a DISTINCTCOUNT() on the date column instead of summing the units.

Defining a range for SUM based on a variable value in another cell

I have explored tons of forums and have found similar situations but no solution.
I have a function in AB3 that counts units sold. Then in cell AB5, I am trying to incorporate a SUM function that only SUMS as many cells as the value that is in AB3.
Example, I sell 107 units in January, I want to SUM the values in Z2:Z108. If I sell 10 units in December then I want to SUM the values in Z2:Z11.
The last formula that I used was =SUM(OFFSET(Z2:Z999,AB3,0)) but it returned the wrong SUM. I can't tell exactly what it's grabbing. I assume I've used this formula incorrectly.
Please help!

How do I compute an average of calculated averages in MS reportviewer/rdlc?

I've searched here and elsewhere on the web and have not found this exact problem/solution.
I'm building an rdlc report using the MS reportViewer - the report I'm creating is based on an existing spreadsheet where the average price across 6 months is calculated individually for each month, then the average of those prices is calculated as the 6 month period average price. Whether I agree with that methodology or if it's correct is irrelevant, I just need to know how to get an rdlc to do this.
For example:
Month Price1 Price2 Delta
May-12 $31.54 $30.03 $1.51
Jun-12 $36.27 $34.60 $1.67
Jul-12 $44.19 $42.00 $2.19
Aug-12 $38.96 $37.06 $1.90
Sep-12 $36.89 $35.08 $1.81
Oct-12 $35.57 $33.97 $1.60
Average $37.24 $35.46 $1.78
(sorry for the lack of a screen snip, I'm new and the system won't let me post an image...)
I've created a tablix that does the monthly averages computation - I use a group in the table to group the 6 months of data by month (and then hide the hourly price data so you only see the month total row) but I'm stuck on how to calculate the bottom row of the table which is the average of each column. (the average of the averages is not the same as the average of all 6 months of prices from the underlying data - that's what I've learned in this process... IOW, that was my first solution :-) )
What I tried to do to get the average of the averages was give the month total cell a name, MonthlyAvgPrice1, then in the bottom row, used this expression:
Avg(reportitems!MonthlyAvgPrice1.Value)
As I kind of expected, this didn't work, when I try to run the report, it gets a build error saying "The Value expression for the textrun 'Price1PeriodAvg.Paragraphs[0].TextRuns[0]' uses an aggregate function on a report item. Aggregate functions can be used only on report items contained in page headers and footers."
Hopfully I've explained this well, does anyone know how to do this?
Thanks!
-JayG
Actually it is not clear from the question that how are you in particular binding the data to the report items, But from the given information what I understand is that you can
Try like this:
Right Click the tablix row and insert a row below
In the cell where you want to have this Average of Averages insert the following expression
=Sum(Fields!Price1.Value)/6
and similarly insert expression =Sum(Fields!Price2.Value)/6 and =Sum(Fields!Delta.Value)/6 in the other cells where you want to display the Averages
Of Course, you will change the Field names Price1,Price2 etc to the fields that you are getting the values from.
HTH

Sql Queries for finding the sales trend

Suppose ,I have a table which has all the billing records. Now I want to see the sales trend for a user given time duration group by each 3 days ...what should be the sql query regarding this?
please help,Otherwise I am gone ...
I can only give a vague suggestion as per the question, however you may want to have a derived column with a standardised date (as per MS date format, just a number per day) that you could then use a modulus (3) on so that days are equal per 3 day period. You can then group and aggregate over this column to get the values for a 3 day period. Obviously to display the date nicely you would have to multiply back and convert your column as well.
Again I'm not sure of the specifics, but I think this general idea could be achieved to get a result (may well not be the best way so it would help to add more to the question...)