in SSRS, I try to create a group structure as in the example below (months have only 5 days here for simplicity). The tricky issue is the last column "Sales(monthly)": It should be a Row Group, grouping by month, after the more detailed columns "Day" and "Sales(daily)". It would be no problem to have this column as the second one between "Month" and "Day" column.
But after being already on the "detail level" with "Day" and "Sales(daily)", I cannot create another more aggregated group. And if I just set Group Properties, Group On to Month for the 4th column, then "Day" and "Sales(daily)" also appear aggregated with only 1 row per month.
Does anybody know how to solve this? Or is this just not possible in SSRS?
Month Day Sales(daily) Sales(monthly)
Feb 1 100 615
2 150
3 130
4 125
5 110
March 1 100 685
2 150
3 200
4 125
5 110
April 1 100 560
2 150
3 75
4 125
5 110
Many thanks
Mike
There's not a native way to do this in SSRS.
You would need use LookupSet to get the daily sales for the month and then use a custom function (SumLookup) to get the total.
Then you need to use an IIF so that you only display it on DAY 1.
=IIF(Fields!DAY.VALUE <> 1, NOTHING,
Code.SumLookup(LookupSet(Fields!MONTH.Value, Fields!MONTH.Value, Fields!SALES.Value, "Dataset1")))
Function code:
Function SumLookup(ByVal items As Object()) As Decimal
If items Is Nothing Then Return Nothing
Dim suma As Decimal = New Decimal()
Dim ct as Integer = New Integer()
suma = 0
ct = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
ct += 1
Next
If (ct = 0) Then return 0 else return suma
End Function
SSRS:
Use LookupSet to retrieve a set of values from the specified dataset
for a name-value pair where there is a 1-to-many relationship. For
example, for a customer identifier in a table, you can use LookupSet
to retrieve all the associated phone numbers for that customer from a
dataset that is not bound to the data region.
Related
I have 2 datasets that I need to populate one table. Dataset 1 contains values that Dataset 2 may not contain. Dataset 2 contains multiple values that I need to get the Sum of. Dataset 2 will always have a matching value (Division_Code) that is contained in Dataset 1.
I need the full list of data from DataSet1, even if no data exists in Dataset2.
Dataset 1 fields:
Division_Code,
Long_Name
Dataset 2 fields:
Division_Code,
TotalBillable,
Date
i.e. Dataset 1:
Division_Code
Long_Name
01
Health
02
Safety
03
Finance
04
Tax
i.e. Dataset 2:
Division_Code
TotalBillable
Date
01
$200
06/01/2022
01
$100
06/08/2022
01
$200
06/12/2022
02
$800
06/01/2022
04
$100
06/05/2022
I need results like this:
Division_Code
Long_Name
Sum(TotalBillable)
01
Health
$500
02
Safety
$800
03
Finance
0
04
Tax
$100
I have tried a variety of Lookups and SumLookup expressions and all result in errors. Can anyone offer guidance on how to write an expression that would accomplish what I need? Thanks in advance.
Use this Custom Code in Report Builder Properties:
Function SumLookup(ByVal items As Object()) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim suma As Decimal = New Decimal()
Dim ct as Integer = New Integer()
suma = 0 ct = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
ct += 1
Next
If (ct = 0) Then return 0 else return suma
End Function
Then use the following expression in your report field
=Code.SumLookup(LookupSet(Fields![LookupDataset1FieldName].Value, Fields![LookupDataset2FieldName].Value, Fields![ResultField].Value, "DataSet2"))
Background:
I am preparng a dataset for a report.
To simplify lets say it is two measures, one Category and a time dimension.
The main Report Parameter is todays date.
I would like to see the first Measure from yesterday (Value 000) and the second measures
from the day before yesterday (Value 001). Because previous days data is not available yet for Value 001.
Lets assume 2020-04-27 is today (passed on from the Reporting Tool SSRS).
AS-IS
SELECT {[Measures].[Value 000], [Measures].[Value 001]} ON COLUMNS
, ( {[DIM Category].[Category].&[1], [DIM Category].[Category].&[2]},
[DIM Date].[Y-M-D ISO].[Date].[2020-04-27].LAG(2): [DIM Date].[Y-M-D ISO].[Date].[2020-04-27].LAG(1)
)
ON ROWS
FROM [My_Cube]
Output:
[Value 000] [Value 001]
Category 1 2020-04-25 88 16
Category 1 2020-04-26 89 (null)
Category 2 2020-04-25 90 14
Category 2 2020-04-26 92 (null)
I tried two MDX-Queries for each date and combined the Sets in the Reporting tool but I am wondering if there is a comfortable way to do that in one MDX query.
The following would be the desired output.
To-Be
Output:
[Value 000] [Value 001]
Category 1 89 16 (Value from day before, for Value 0001)
Category 2 92 14
The Date doesn't need to be shown in the output (but can be)
You can solve the issue by using calculated measures. Follwoing example is based on adventureworks . I want to rebuild your senario for Jan 23 2013
The initial query is there to show values for yesterday abd day before
with
member measures.Yesterday
as
sum([Date].[Date].currentmember.lag(1),[Measures].[Internet Sales Amount])
member measures.DayBefore
as
sum([Date].[Date].currentmember.lag(2),[Measures].[Internet Sales Amount])
select
{
[Measures].[Internet Sales Amount],measures.Yesterday ,measures.DayBefore
}
on columns,
{
([Product].[Category].[Category],[Date].[Date].&[20130120]:[Date].[Date].&[20130123])
}
on rows
from
[Adventure Works]
where [Date].[Date].&[20130123]
Result
Now lets remove the date from the rows and put it in where
with
member measures.Yesterday
as
sum([Date].[Date].currentmember.lag(1),[Measures].[Internet Sales Amount])
member measures.DayBefore
as
sum([Date].[Date].currentmember.lag(2),[Measures].[Internet Sales Amount])
select
{
[Measures].[Internet Sales Amount],measures.Yesterday ,measures.DayBefore
}
on columns,
{
([Product].[Category].[Category])
}
on rows
from
[Adventure Works]
where [Date].[Date].&[20130123]
Result
Is there a way to use an Over and Intersect function to get the average sales for the first 3 periods (not always consecutive months, sometimes a month is skipped) for each Employee?
For example:
EmpID 1 is 71.67 ((80 + 60 + 75)/3) despite skipping "3/1/2007"
EmpID 3 is 250 ((350 + 250 + 150)/3).
I'm not sure how EmpID 2 would work because there are just two data points.
I've used a work-around by calculated column using DenseRank over Date, "asc", EmpID and then used another Boolean calculated column where DenseRank column name is <= 3, then used Over functions over the Boolean=TRUE column but I want to figure the correct way to do this.
There are Last 'n' Period functions but I haven't seen anything resembling a First 'n' Period function.
EmpID Date Sales
1 1/1/2007 80
1 2/1/2007 60
1 4/1/2007 75
1 5/1/2007 30
1 9/1/2007 100
2 2/1/2007 200
2 3/1/2007 100
3 12/1/2006 350
3 1/1/2007 250
3 3/1/2007 150
3 4/1/2007 275
3 8/1/2007 375
3 9/1/2007 475
3 10/1/2007 300
3 12/1/2007 200
I suppose the solution depends on where you want this data represented, but here is one example
If((Rank([Date],"asc",[EmpID])<=3) and (Max(Rank([Date],"asc",[EmpID])) OVER ([EmpID])>=3),Avg([Sales]) over ([EmpID]))
You can insert this as a calculated column and it will give you what you want (assuming your data is sorted by date when imported).
You may want to see the row numbering, and in that case insert this as a calculated column as well and name it RN
Rank([Date],"asc",[EmpID])
Explanation
Rank([Date],"asc",[EmpID])
This part of the function is basically applying a row number (labeled as RN in the results below) to each EmpID grouping.
Rank([Date],"asc",[EmpID])<=3
This is how we are taking the top 3 rows regardless if Months are skipped. If your data isn't sorted, we'd have to create one additional calculated column but the same logic applies.
(Max(Rank([Date],"asc",[EmpID])) OVER ([EmpID])>=3)
This is where we are basically ignoring EmpID = 2, or any EmpID who doesn't have at least 3 rows. Removing this would give you the average (dynamically) for each EmpID based on their first 1, 2, or 3 months respectively.
Avg([Sales]) over ([EmpID])
Now that our data is limited to the rows we care about, just take the average for each EmpID.
#Chris- Here is the solution I came up with
Step 1: Inserted a calculated column 'rank' with the expression below
DenseRank([Date],"asc",[EmpID])
Step 2: Created a cross table visualization from the data table and limited data with the expression below
I am working on SSRS reporting and want to summarize (sum) the amount field and narrow the output of the report. As you can see on the below table, the data source has a date field which is unique for each row which make it difficult for me to summarize the output. I want the date field only for filtering purpose, I don't want to show the date data in the details of the report. But since the date field is there in the data which is returned by the query, and I am trying to filter the report using date field, I couldn't be able to summarize it (sum the amount field).
Any Idea?
current data set on SSRS returns the following result
id item date amount
1 item 1 1/1/2015 1200
1 item 1 1/2/2015 1200
1 item 1 1/3/2015 1200
1 item 2 1/4/2015 100
1 item 2 1/5/2015 100
1 item 2 1/6/2015 100
My need (when I filter the report with: where date > = 1/1/2015 and date <= 1/6/2015)
id Item Amount
1 item 1 3600
1 item2 300
Since you are summarizing the data in SSRS you just the group level not the detail section.
Create a Group by Item
Delete the detail section by clicking on the tablix.
Put the expression of the textbox =SUM(Fields!Amount.Value)
The other way to handle this scenario is to modify your query and group by in query by the item while adding the Date filter in the where clause.
I need some help with this issue in SSRS to find the YTD(%) for the YTD columns..
I have SSRS 2008 tablix region where the columns are State,Category,January, February, March,...,December, YTD. These columns have both the sums and the percentage values depending on the row. I need help to calculate the YTD when the column is %.
example:
State Category January February March...... YTD
MN A 200 200 0...... 400
MN B 21 12 0........ 33
MN A% 12.5 12.5 0........ ??
For A,B above, the YTD is simply adding the report items January+February+March+.... which will be 400 and 33 as shown(assuming only Jan and Feb have real values > 0).
For the row A% above(??), since this a percent column, my YTD should be the average of the non-null/non-zero columns...in this case (12.5+12.5)/2=12.5 but I am unable to find out the count of the non-null columns for each category (January, February, etc)...I have tried avg,count, sum, etc but i am not getting the correct value. If I can figure out the denomintor(which will be the count of the non-null columns in January, February,...,December), the problem will be solved as I can then do:
( Jan+Feb+March+...+Dec)/Count(Jan,Feb,Mar,..,Dec)
The Count should return me the count of the non-null/non-zero columns only so I can do the average calculation..please help.
I am not sure what you want.
If all that you want is to find out average of a row in the last column you can do this:
Make the expression of the column in which you want average like this:
Sum(Fields!Jan.Value + Fields!Feb.Value...+Fields!Dec.Value)/
Sum(IIF(IsNothing(Fields!Jan.Value),0,1) +
IIF(IsNothing(Fields!Feb.Value),0,1) +
.
.
IIF(IsNothing(Fields!Dec.Value),0,1)
)
so, in the denominator, you are doing this:
Sum(1+0+1+1+0...+0)
i.e. 1 is returned if Field is not null, otherwise 0