I'm trying to sum a net balance based on the earliest date in an SSRS report. In this case there are only 2 dates, but there can be more dates not more than 7 days.
Here's a sample of my data:
Here's what I'm trying to get with the earliest date of 10/26/15:
I've tried the following code, but not able to get this to work:
=Sum(IIf(DateDiff("d",Fields!SettleFullDate.Value,today())>=7
and DateDiff("d", Fields!SettleFullDate.Value, today())<7
and Fields!SETTLEBALANCE.Value>0), Fields!SETTLEBALANCE.Value, 0)
Update: I tried the code below and keep getting an error on the report. Could it be that I need to change the date field to an integer?
Thanks in advance for your help!
To compare the sum of values of two dates, the maximum and minimum in a set you can use the following equation
=Sum(iif(Fields!myDate.Value = Max(Fields!myDate.Value), Fields!myVal.Value, 0))
-Sum(iif(Fields!myDate.Value = MIN(Fields!myDate.Value), Fields!myVal.Value, 0))
This Sums all the values that match the maximum date in the dataset together, and sums all the values that match the minimum date in the dataset together, and takes one from the other.
It is irrespective of which dates you ask to be received, the above approach will work only against the records that you return to SSRS. So if you have a filter (WHERE clause) to return records between Date1 and Date2 this will still apply (Note - don't actually use 'Between' in the query)
Rather than using the maximum and minimum dates as listed here, you could also calculate a date similar to your original approach using
dateadd("d", -7, Fields!MySpecificDate.Value)
And insert that to the expression above.
Hopefully this is what you require - if not please let me know.
Related
I have a form called FirstInLastOut which looks as the image below.
Based on Name or badge number I want to search between two dates.
I am using the following criteria on the query:
>=[Forms]![FirstInLastOut]![StartDateEntry] And <=[Forms]![FirstInLastOut]![EndDateEntry]
This is given me results that include other months as well. Please see the query report below.
So as you can see in the image the numbers of the dates are falling with the the parameter but getting other months as well.
How can I make it so it will only select the dates between the date ranges?
SELECT FistClockInRaw.Badgenumber, FistClockInRaw.name, FistClockInRaw.lastname, FistClockInRaw.MinOfCHECKTIME, FLastClockOutRaw.MaxOfCHECKTIME, [MaxOfCHECKTIME]-[MinOfCHECKTIME] AS TotalHours, FLastClockOutRaw.QDate, FistClockInRaw.MinOfQTime, FLastClockOutRaw.MaxOfQTime, RawCompleteQuery.CHECKTIME
FROM RawCompleteQuery, FLastClockOutRaw INNER JOIN FistClockInRaw ON (FLastClockOutRaw.Badgenumber = FistClockInRaw.Badgenumber) AND (FLastClockOutRaw.name = FistClockInRaw.name) AND (FLastClockOutRaw.QDate = FistClockInRaw.QDate)
WHERE (((FistClockInRaw.name)=[Forms]![FirstInLastOut]![FirstNameEntry]) AND ((RawCompleteQuery.CHECKTIME)>=[Forms]![FirstInLastOut]![StartDateEntry] And (RawCompleteQuery.CHECKTIME)<=[Forms]![FirstInLastOut]![EndDateEntry]));
is the Query
I assume that the forms fields StartDateEntry and EndDateEntry are bound to fields of type date.
I also assume that you are only interested to compare the date part of those form fields.
So try this condition instead to assure correct date interpreting:
WHERE FistClockInRaw.name=[Forms]![FirstInLastOut]![FirstNameEntry]
AND RawCompleteQuery.CHECKTIME >= Format([Forms]![FirstInLastOut]![StartDateEntry], "\#yyyy-mm-dd\#")
AND RawCompleteQuery.CHECKTIME <= Format([Forms]![FirstInLastOut]![EndDateEntry], "\#yyyy-mm-dd\#")
A remark:
Be aware that every date field/variable always contains a time part too!
So your current logic comparing EndDateEntry with <= can cause trouble, because you would only get results of the end date having time values of 00:00:00 in the field CHECKTIME.
If any record of CHECKTIME contains the requested end date and a time part bigger then 00:00:00, it is not in the result.
To avoid that, you should use < and add one day:
And RawCompleteQuery.CHECKTIME < Format([Forms]![FirstInLastOut]![EndDateEntry] + 1, "\#yyyy-mm-dd\#")
I have 3 months of AR data. From SQL I am populating details records for 3 months. In SSRS I am grouping the totals by month and showing only group summary. I want to calculate the variance by difference between current month and previous month. Please see the attached output file.
Could anyone help me on finding the variance at group level. How do I calculate the difference by using previous function?
Is there any way to find individual group sum of the particular field like this one
Sum(Fields!Current.Value, "DataSet1")
Something like this perhaps?
=Sum(iif(month(Fields!myDate.Value) = month(Max(Fields!myDate.Value)), Fields!myVal.Value, 0))
-Sum(iif(month(Fields!myDate.Value) = month(dateadd("M", -1, max(Fields!myDate.Value))), Fields!myVal.Value, 0))
Where myDate is the date used to group the months on, and myVal is the specific data for the column
UPDATE
Using this dataset
EOM myValue
09/30/2015 2
10/31/2015 6
11/30/2015 19
Gives this basic report
You can then use this formula (based on the original one in the original answer above) to determine the difference between the last and the penultimate row
=Sum(
iif(month(CDate(Fields!EOM.Value)) = month(Max(Fields!EOM.Value)),
Fields!myValue.Value,
0)
)
-Sum(iif(month(CDate(Fields!EOM.Value)) = month(dateadd("M", -1, max(CDate(Fields!EOM.Value)))),
Fields!myValue.Value,
0)
)
Then place this in the footer of the tablix as shown
This shows the difference between the two rows
Is this the behaviour you require? If not please clarify further in the original question as an update/edit.
I've this report
Here I make the first sum because I've grouped values from each month (months are "Gennaio", "Febbraio", "Marzo" etc etc.). These values are hidden, but anyway I get the sum and I display the sum for each month.
Then I should make the second sum that use values for each month and display the total for each category. Categories are "TOTALE LAVORI RESTAURO", "TOTALE LAVORI EDILE" etc.)
This is the final sum, where I sum values from each category.
Everything is working well, but now I have to add a "month" parameter to the report that returns sums until a selected month. This parameter changes the sum 1 with this expression:
=Sum(IIf(Fields!mese.Value <= Parameters!mese.Value, Fields!costi.Value, 0))
Now, how should I change expression in SUM2 and SUM3 to work with this parameter?
If I copy that code, ther returns #Error and as far as I know I can't use ReportItems sum.
So any suggestion?
SUM #1 could remain Sum(Fields!costi.Value) because you need to display every months.
i.e.: display GIUGNO even if Parameters!mese.Value = 4 (APRILE).
So you have only to change SUM #2 and #3 because TOTALE LAVORI RESTAURO and TOTALI must show only costi from GENNAIO to Parameters!mese.Value; i.e. if Parameters!mese.Value = 4 display only GENNAIO-APRILE even if we have details about GIUGNO.
The expression gave error because you have NULL value in Fields!costi.Value or Fields!mese.Value: convert this value to zero in your DataSet and you won't have problems.
I have an SSRS report which gets filtered with the following expression:
="{[Claim Cheque].[Cheque Date].&[" + format(Parameters!StartDate.Value, "yyyy-MM-dd") + "T00:00:00]:[Claim Cheque].[Cheque Date].&[" + format(Parameters!EndDate.Value, "yyyy-MM-dd") + "T00:00:00]}"
which works fine. My problem is I don't have cheques everyday and this makes the query return no results. As an example I'm choosing the date range from 1st to 20th of November. I have cheques in 14th and 15th but NOT 20th. I will miss 14th and 15th results in my report this way.
I know how to force the parameters to get only existing values in the cube. but I need to be able to select all dates. Is there any other way to make this expression return desired results?
Any help is appreciated.
It looks to me like you have a separate date dimension just for [Cheque Date], rather than linking back to a fully populated master date dimension. Take a look at the way Order Date and Ship Date dimensions are done in the AdventureWorks sample. They are explained nicely here: Role-playing dimensions
I was able to run MDX queries like yours against that data, where there were no transactions on the start and end dates of the range:
Select
[Measures].[Order Count] on 0,
[Sales Channel].&[Reseller] on 1
From [Adventure Works]
Where {[Ship Date].[Fiscal].[Date].&[20060701]:[Ship Date].[Fiscal].[Date].&[20060710]}
and
Select
[Measures].[Order Count] on 0,
([Sales Channel].&[Reseller],
{[Ship Date].[Fiscal].[Date].&[20060701]:[Ship Date].[Fiscal].[Date].&[20060710]}) on 1
From [Adventure Works]
If I have MySQL query like this, summing word frequencies per week:
SELECT
SUM(`city`),
SUM(`officers`),
SUM(`uk`),
SUM(`wednesday`),
DATE_FORMAT(`dateTime`, '%d/%m/%Y')
FROM myTable
WHERE dateTime BETWEEN '2011-09-28 18:00:00' AND '2011-10-29 18:59:00'
GROUP BY WEEK(dateTime)
The results given by MySQL take the first value of column dateTime, in this case 28/09/2011 which happens to be a Saturday.
Is it possible to adjust the query in MySQL to show the date upon which the week commences, even if there is no data available, so that for the above, 2011-09-28 would be replaced with 2011/09/26 instead? That is, the date of the start of the week, being a Monday. Or would it be better to adjust the dates programmatically after the query has run?
The dateTime column is in format 2011/10/02 12:05:00
It is possible to do it in SQL but it would be better to do it in your program code as it would be more efficient and easier. Also, while MySQL accepts your query, it doesn't quite make sense - you have DATE_FORMAT(dateTime, '%d/%m/%Y') in select's field list while you group by WEEK(dateTime). This means that the DB engine has to select random date from current group (week) for each row. Ie consider you have records for 27.09.2011, 28.09.2011 and 29.09.2011 - they all fall onto same week, so in the final resultset only one row is generated for those three records. Now which date out of those three should be picked for the DATE_FORMAT() call? Answer would be somewhat simpler if there is ORDER BY in the query but it still doesn't quite make sense to use fields/expressions in the field list which aren't in GROUP BY or which aren't aggregates. You should really return the week number in the select list (instead of DATE_FORMAT call) and then in your code calculate the start and end dates from it.