calculate the sum of a column based on another column values(SSRS) - reporting-services

The data is as shown below(Source description and total shares) are the two columns
Source 494,482,729,319.98998
Initial
Filtered
Final 494,482,729,319.98998
My expression throws an #Error in output of the report(preview section)
=SUM( Fields!total_shares.Value *
SWITCH(Fields!Source_Description.Value = "Initial" OR Fields!Source_Description.Value = "Inserted", 1,
Fields!Source_Description.Value = "Filtered" OR Fields!Source_Description.Value = "Deleted" OR Fields!Source_Description.Value = "Final", -1,
True,0
)
)
Can you please help me where am I going wrong?

Related

How do I hide columns in SSRS with TWO conditions?

I've got a report with a ColumnA that needs to be hidden if to specific values for parameters are met.
Join(Parameters!vExclude.Value,",").Contains(0)=True
and
Parameters!vType.Value = 1
I've tried
= Join(Parameters!vExclude.Value,",").Contains(0)=True and Parameters!vType.Value = 1
= iif(Join(Parameters!vExclude.Value,",").Contains(0)=True and Parameters!vType.Value = 1, true, false)
and it doesn't produce an error, yet one condition is always ignored.
Any suggestions?

SSRS - Expression to count the rows for currentdate match or (parameter selected date) with some equivalent other columns

In SSRS Expression, how to count the numbers of rows that present in today or yesterday in dataset with other equivalent condition,
For example
=COUNT(IIF(
DateDiff(DateInterval.Day,Cdate("01/01/1900"),Fields!Opendate.Value) =
DateDiff(DateInterval.Day,Cdate("01/01/1900"), Now()), Fields!Opendate.Value, Nothing))
Using this expression I can check get the total count for today, it's working.
I need to add to check today date with other condition like:
If (today date and Fields!reason.Value = "Other")
It's not working when I add reason value to check :
=COUNT(IIF(
DateDiff(DateInterval.Day, Cdate("01/01/1900"), Fields!Opendate.Value) =
DateDiff(DateInterval.Day, Cdate("01/01/1900"), Now()) -1, Fields!Opendate.Value, Nothing ) **And Fields!reason.Value = "Other"**)
Please guide me
Just add it in your IIF() statement:
=COUNT(IIF(
DateDiff(DateInterval.Day, Cdate("01/01/1900"), Fields!Opendate.Value) =
DateDiff(DateInterval.Day, Cdate("01/01/1900")
And Fields!reason.Value = "Other",
Now()) -1,
Fields!Opendate.Value,
Nothing
)
)

create a set expression for a cell in a table report

I have a report which creates a spreadsheet. one cell could have data from one of three fields depending on a fourth field status or field two being blank..
I was thinking of writing as CASE statement but that does not work in ssrs.
The IIF statement works great for 2 values but how do you write for three values?
In common language it would be "If secondary value ="Yes", use secondary name, If account field value is Null, use Contact field value, otherwise use account field value"
Thanks
You can use nested IIF statements but they quickly get messy. You should use SWITCH which acts a bit like a case statement.
A simple example would be
= SWITCH(
Fields!myFirstField.Value = <10 , "Small",
Fields!myFirstField.Value = <30 , "Medium",
Fields!myFirstField.Value = <80 , "Large",
True , "HUGE",
)
As switch stops at the first true expression there is not need to check ranges of values if you get them in the correct order.
The final "True" expression just acts like an ELSE
If you need to check multiple criteria per condition then you can do that too like this..
= SWITCH(
Fields!myFirstField.Value = <10 AND Fields!mySecondField.Value = 1 , "Small Cat",
Fields!myFirstField.Value = <10 AND Fields!mySecondField.Value = 2 , "Small Dog",
Fields!myFirstField.Value = <30 , "Medium Animal",
Fields!myFirstField.Value = <80 , "Large Animal",
True , "HUGE Animal",
)

SSRS : How to aggregate on certain values of a column?

I have a column (Say PriceA) in SSRS which gets populated based of Expression.
PriceA.value
IIF((Fields!MOP.Value = "PRIV" OR Fields!MOP.Value = "FACI" OR Fields!MOP.Value = "GUAR" OR Fields!MOP.Value = "CASH"
OR Fields!MOP.Value = "CHRG" OR Fields!MOP.Value = "INV"),
IIF(Fields!UDRx.Value,"U/D",Fields!TtlPrice.Value),
IIF(Fields!elecadj.Value="0" AND Fields!elecadj2.Value="0", IIF(Fields!UDRx.Value,"U/D",IIF(Fields!MOP2.Value="0",Fields!Copay.Value,"")),
IIF(Fields!UDRx.Value,"U/D",Fields!PatientPayAmt.Value)
)
)
The Value in PriceA can be "U/D" or Zero or some value as "150.00". Now I want to display at the end of the report, an aggregate of the rows in that column, discarding the values $0.0 and "U/D".
How do I do that?
I also have another column where it shows values based off off 2 different expression, that I need to aggregate. That one is not working either.
2ndPriceA_expression
IIF((Fields!MOP.Value = "PRIV" OR Fields!MOP.Value = "FACI" OR Fields!MOP.Value = "GUAR" OR Fields!MOP.Value = "CASH"
OR Fields!MOP.Value = "CHRG" OR Fields!MOP.Value = "INV"), " ",
IIF(Fields!elecadj.Value="0" AND Fields!elecadj2.Value="0",
IIF(Fields!UDRx.Value="0",Format(Fields!TtlPrice.Value,"C"),"U/D") ,
IIF(Fields!UDRx.Value="0",Format(Fields!Payor1PaidAmt.Value,"C"),"U/D")
)
)
2ndPriceB_expression
IIF(Fields!MOP2.Value<>"",
IIF(Fields!elecadj.Value="0" and Fields!elecadj2.Value="0"
,IIF(Fields!UDRx.Value="1","U/D",Fields!Copay.Value)
,IIF(Fields!UDRx.Value="1"
,"U/D"
,IIF(Fields!elecadj2.Value="0"
,Fields!Copay.Value
,Fields!Payor2PaidAmt.Value
)
)
)
," ")
I need to show aggregate of 2ndPriceA & 2ndPriceB in a 3rd cell. Sorry I'm 2 weeks new to SSRS.
Thanks in advance. any help is appreciated.
Just do a SUM() of an IIF() expression that will filter out the values you don't want to SUM.

SSRS 2012. Replicate grouping results in report in Query Designer

New to SSRS 2012 & struggling.
I have a report - containing a subreport - on client data. When testing with one client (just to make sure everything was OK) it works perfectly.
When the filter's removed, it's timing out (it's actually saying it's been cancelled by the user, which it hasn't).
Obviously the inclusion of the subreport is the problem (as the main report runs fine without it).
My subreport can validly return multiple records per client. The subreport is grouped on ClientId. I then have a calculated field - say HasIP - that concatenates two fields (IC and PC ) to produce either YesYes or YesNo. The tablix is sorted by HasIP by Z to A.
The info in the ClientID footer are what I'm displaying.
ClientID HasIP
22 YesNo - has two records, but since it has a YesYes, I don't want this one
22 YesYes - has two records, but I want the this one
52 YesYes - may only have 1 record, I want this record
76 YesNo - may only have 1 record, I want this record
Theoretically a client can't have more than one instance of HasIP=YesYes & shouldn't have more than 2 records. How can I recreate this effect in Query Designer? Essentially if HasIP=yesyes, use that record, otherwise use the other record
If I can do this, I can then drop the subreport completely, add this dataset to my main report & use Lookup to get the data.
However, the way our report scenario is set up, I'm not permitted to change the query [I have to click Query Designer button in Dataset Properties] & I have no experience in MDX.
SOLVED!!!:
OK - here's what I've come up with.
Assign numeric order to IC and PC values
I concatenated the IC & PC field values together and assigned values and added the ID of the records in the original subreport. I called this field HasIP
=Switch(Fields!IC.Value+Fields!PC.Value="YesYes", 1,
Fields!IC.Value+Fields!PC.Value="YesNo", 2,
Fields!IC.Value+Fields!PC.Value="NoNo", 3) & "-" & Fields!R_Name.Value
This left me with 2-xxxx, 1-yyyy etc.
I then added a filter to my second dataset:
=Left(Fields!HasIP.Value, 1)
to exclude values of "NoNo"
Concatenate HasIP and other fields in Dataset2 (to be used by LookupSet)
In addition also had to convert the text values into code for output (eg Yes = 1, No = 2, Unknown = 3 etc). I did this by creating a calculated field in Dataset2 (in the report, not the query) which included the HasIP. I delimited HasIP from the value by using a dollar sign.
=Fields!HasIP.Value & "$" &
SWITCH(
left(Fields!CoR.Value, 1)="C", 1,
Left(Fields!CoR.Value, 1)="N", 2,
True, ""
)
This left me with 2-xxxx$2, 1-yyyy$1 etc.
Sort the LookupSet results
LookupSet creates an array (and yes, now you know too). I needed to sort this so that the one I'm after is the first value returned. This is achieved by copying and pasting the following into the custom code section of your report. (I've added the code to allow you to sort in reverse if you need it).
Function JoinSorted(m_Array As Object()) As String()
System.Array.Sort(m_Array)
' Array.Reverse(m_Array) 'uncomment this line if you want to sort in reverse
Dim k As Integer = 0
For i As Integer = 0 To m_Array.Length - 1
If i > 0 AndAlso m_Array(i).Equals(m_Array(i - 1)) Then
Continue For
End If
m_Array(k) = m_Array(i)
k += 1
Next
Dim fred As [String]() = New [String](k - 1) {}
System.Array.Copy(m_Array, 0, fred, 0, k)
Return fred
End Function
You call this by using the following in your report expression:
Join(
Code.JoinSorted(
LookupSet(Fields!Main_ID.Value,Fields!Main_ID.Value,Fields!YourField.Value,"Dataset2")
),""
)
So, regardless of how LookupSet wanted to return the array, I always got 1-yyyy$1 first.
Handling LookupSet output on the report - include default for no records
For some LookupSet results in the report, I needed return a default value if there were no records returned. Otherwise I needed to return the assigned value (1, 2, 3 etc). If found two ways to do this.
This checks to see if the array count [yes, by using length] is greater than zero. If so, then using a mid function on the array result to return the 14th character:
=SWITCH(
LookupSet(
Fields!Main_ID.Value, Fields!Main_ID.Value, Fields!Record_Name.Value, "Dataset2"
)
.Length=0,
2,
LookupSet(
Fields!Main_ID.Value, Fields!Main_ID.Value, Fields!Record_Name.Value, "Dataset2")
.Length>0,
1)
OR
This is the same:
=iif(
LookupSet(
Fields!Main_ID.Value,Fields!Main_ID.Value,Fields!Main_ID.Value,"Dataset2"
).Length>0,
Mid(
Split(
Join(
Code.JoinSorted(
LookupSet(
Fields!Main_ID.Value,Fields!Main_ID.Value,Fields!Main_ID.Value,"Dataset2")
)
,";")
,";").GetValue(0)
, 'start point of mid
InStr(
Join(
Code.JoinSorted(
LookupSet(
Fields!Main_ID.Value,Fields!Main_ID.Value,Fields!Main_ID.Value,"Dataset2"
)
)
,";")
,"$")
+1,
1),
"2"
)
Handling LookupSet output on the report - using of MID when length of value varies
In some cases the value I needed to return varied in length, eg 2 or 10. I also needed to return nothing if the LookupSet didn't return any results. I couldn't use "normal" versions of MID like this:
Mid(
Join(Code.JoinSorted(
LookupSet(Fields!Main_ID.Value,Fields!Main_ID.Value,Fields!Q12d.Value,"Dataset2")),
";"),
InStr(
Join(
Code.JoinSorted(
LookupSet(Fields!Main_ID.Value,Fields!Main_ID.Value,Fields!Q12d.Value,"Dataset2")
),
";"),
"$")+1,
(
InStr(
Join(
Code.JoinSorted(
LookupSet(Fields!Main_ID.Value,Fields!Main_ID.Value,Fields!Q12d.Value,"Dataset2")
),
";"),
";")
-
InStr(
Join(
Code.JoinSorted(
LookupSet(Fields!Main_ID.Value,Fields!Main_ID.Value,Fields!Q12d.Value,"Dataset2")
),
";"),
"$")
- 1)
)
as it threw #ERROR due to the use of -1 (at the end) making the string a negative length for some records.
So, here is what I could use:
=
Mid(
Split(
Join(
Code.JoinSorted(
LookupSet(Fields!Main_ID.Value,Fields!Main_ID.Value,Fields!Q12b.Value,"Dataset2")
),
";"),
";").GetValue(0)
,
InStr(
Join(
Code.JoinSorted(
LookupSet(
Fields!Main_ID.Value,Fields!Main_ID.Value,Fields!Q12b.Value,"Dataset2")
),
";"),
"$")
+1,
1)
By doing this, I could get the results I was after in the details & the footer.
I hope this can help someone else.