SSRS Expression - count on 1 field, iif on 2nd field
Here is a sample of my data:
What I need is to get the distinct count of Apples where Oranges is not blank. I currently have the expression below, but it doesn't return a distinct count, and I need it to count Apples rather than Oranges.
=sum(IIF(isnothing(Fields!Oranges.Value) = false,1,0))
This would return a sum of 5. The sum I need is 3.
Hi ,
you can use below;
=CountDistinct(IIF(Isnothing(Fields!Orange.Value),0,Fields!Orange.Value))-1
Thanks
Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem. http://techequation.com
Similar Messages
-
Hi All;
I have a field called createdon
Using this field i need to create the SSRS expression for the table as below
Any help much appreciated
Thanks
Pradnya07use expressions as below
assuming this is to be done in SSRS
Today
=COUNT(IIF(
DateDiff(DateInterval.Day,Cdate("01/01/1900"),Fields!createdon.Value) = DateDiff(DateInterval.Day,Cdate("01/01/1900"),Now()),Fields!YourRequiredField.Value,Nothing))
Yesterday
=COUNT(IIF(
DateDiff(DateInterval.Day,Cdate("01/01/1900"),Fields!createdon.Value) = DateDiff(DateInterval.Day,Cdate("01/01/1900"),Now())-1,Fields!YourRequiredField.Value,Nothing))
LastWeek
=COUNT(IIF(
DateDiff(DateInterval.Week,Cdate("01/01/1900"),Fields!createdon.Value) = DateDiff(DateInterval.Week,Cdate("01/01/1900"),Now())-1,Fields!YourRequiredField.Value,Nothing))
Last fortnight
=COUNT(IIF(
(DateDiff(DateInterval.Week,Cdate("01/01/1900"),Fields!createdon.Value) = DateDiff(DateInterval.Week,Cdate("01/01/1900"),Now())-1)
Or (DateDiff(DateInterval.Week,Cdate("01/01/1900"),Fields!createdon.Value) = DateDiff(DateInterval.Week,Cdate("01/01/1900"),Now())-2),Fields!YourRequiredField.Value,Nothing))
Last Month
=COUNT(IIF(DateDiff(DateInterval.Month,Cdate("01/01/1900"),Fields!createdon.Value) = DateDiff(DateInterval.Month,Cdate("01/01/1900"),Now())-1,Fields!YourRequiredField.Value,Nothing))
Year To Date
=COUNT(IIF(DateDiff(DateInterval.Year,Cdate("01/01/1900"),Fields!createdon.Value) = DateDiff(DateInterval.Year,Cdate("01/01/1900"),Now())
And
DateDiff(DateInterval.Day,Cdate("01/01/1900"),Fields!createdon.Value) <= DateDiff(DateInterval.Day,Cdate("01/01/1900"),Now()),Fields!YourRequiredField.Value,Nothing))
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
SSRS Expression for Conditional Filtering using the "IN" operator
Hello,
I need to filter my dataset based on a parameter:
If Period= 1 then Week must be in (W1, W2, W3), Else Week must be in (W10, W20, W30)
I tried using the "IN" operator but don't know how to create the expression for the "Value" field. I tried the following:
iif(Parameters!Period.Value = 1,
"W1, W2, W3",
"W10, W20, W30")
But it doesn't work.
Expression: Week
Operator: IN
Value: ???
Any help would be highly appreciated!Hi,
Use split function.
See this expression: IIF(Parameters!Period.Value = 1, SPLIT("W1,W2,W3",","), SPLIT("W10,W20,W30",","))
http://social.msdn.microsoft.com/Forums/sqlserver/en-US/8da78c9b-7f0c-42f1-a9c4-82f065f317c9/using-the-in-operator-in-ssrs-expressions
Thanks Shiven:) If Answer is Helpful, Please Vote -
SSRS expression returns #error value in some cells
Hello,
What do you think below expression sometimes return #error value in ssrs.
=SUM(Fields!X.Value / 100 * DateDiff(DateInterval.Day,Fields!s_date.Value,Fields!e_date.Value)) /
IIF( SUM(DateDiff(DateInterval.Day,Fields!s_date.Value,Fields!e_date.Value)) = 0
,nothing
,SUM(DateDiff(DateInterval.Day,Fields!s_date.Value,Fields!e_date.Value))Hi,
Use below expression to overcome the issue:
=
IIF( SUM(DateDiff(DateInterval.Day,Fields!s_date.Value,Fields!e_date.Value)) = 0
, 0
, SUM( Fields!X.Value / 100
* DateDiff(DateInterval.Day,Fields!s_date.Value,Fields!e_date.Value)
SUM(DateDiff(DateInterval.Day,Fields!s_date.Value,Fields!e_date.Value))
Thanks, Madhu
Hi madhu,
I have value for Month field as 0. I have used MonthName function in the report. So im getting error as #Error
Expression:
MONTHNAME(Fields!Month.Value)& " "& Fields!Day.Value &" "& Fields!Year.Value
Please help me to resolve the issue.
Thanks in Advance..
Regards,
LuckyAbdul -
Hello, Expert,
Could you please help me with the following problem? Thanks in advance!
I have designed the matrix report (SSRS 2012) with database table structure looks like below.
Week
Version
Count
Week1
V1.1
4000
Week1
V1.2
4000
Week1
V1.3
4000
Week2
V1.1
3000
Week2
V1.2
3000
Week2
V1.3
3000
Week3
V1.1
2000
Week3
V1.2
2000
Week3
V1.3
2000
Week4
V1.1
1000
Week4
V1.2
1000
Week4
V1.3
1000
The matrix report displays like below. Column grows based on no of Week in the table.
Week1
Week2
Week3
Week4
V1.1
4000
3000
2000
1000
V1.2
4000
3000
2000
1000
V1.3
4000
3000
2000
1000
What I want to do now is: instead of the Count values, I need to calculate the percentage of each week over the
Count in Week1 so that each cell displays Count(Week2)/Count(Week1), Count(Week3)/Count(Week1), etc. What is the SSRS expression for that? I’m new to SSRS, Please help!Heidi,
Thank you so much for your reply and solution! Now I know how to get the first field in a group. But I can't apply your solution directly just yet because in order to explain my problem I simplified my data structure. My real data structure has a nested
group like this:
Week VersionMajor VersionMinor Count
Week1 V1 V1.1 2000
Week2 V1 V1.1 1500
Week3 V1 V1.1 800
Week1 V1 V1.2 1000
Week2 V1 V1.2 500
Week3 V1 V1.2 200
Week1 V1 V1.1 2000
Week2 V1 V1.1 1500
Week3 V1 V1.1 800
Week1 V1 V1.2 1000
Week2 V1 V1.2 500
Week3 V1 V1.2 200
Here is the query for the above data:
SELECT 'Week1' AS Week, 'V1' AS VersionMajor, 'V1.1' AS VersionMinor, 2000 AS Count
UNION ALL
SELECT 'Week2' AS Week, 'V1' AS VersionMajor, 'V1.1' AS VersionMinor, 1500 AS Count
UNION ALL
SELECT 'Week3' AS Week, 'V1' AS VersionMajor, 'V1.1' AS VersionMinor, 800 AS Count
UNION ALL
SELECT 'Week1' AS Week, 'V1' AS VersionMajor, 'V1.2' AS VersionMinor, 1000 AS Count
UNION ALL
SELECT 'Week2' AS Week, 'V1' AS VersionMajor, 'V1.2' AS VersionMinor, 500 AS Count
UNION ALL
SELECT 'Week3' AS Week, 'V1' AS VersionMajor, 'V1.2' AS VersionMinor, 200 AS Count
UNION ALL
SELECT 'Week1' AS Week, 'V1' AS VersionMajor, 'V1.1' AS VersionMinor, 2000 AS Count
UNION ALL
SELECT 'Week2' AS Week, 'V1' AS VersionMajor, 'V1.1' AS VersionMinor, 1500 AS Count
UNION ALL
SELECT 'Week3' AS Week, 'V1' AS VersionMajor, 'V1.1' AS VersionMinor, 800 AS Count
UNION ALL
SELECT 'Week1' AS Week, 'V1' AS VersionMajor, 'V1.2' AS VersionMinor, 1000 AS Count
UNION ALL
SELECT 'Week2' AS Week, 'V1' AS VersionMajor, 'V1.2' AS VersionMinor, 500 AS Count
UNION ALL
SELECT 'Week3' AS Week, 'V1' AS VersionMajor, 'V1.2' AS VersionMinor, 200 AS Count
And my matrix table looks like this:
What I need to do is to calculate the percentage of each week over week1 for
1) V1 Total
2) V1.1
3) V1.2
I can't use your solution directly because I need to apply Sum function for each cell and the Sum function gives me error when I try to use it on the denominator
First(Fields!Count.Value,"VersionMinor"). If you could help me further to get to the final solution, I'd really appreciate it!!
Happy New Year! -
How to apply Like Operator in SSRS expression.
HI All,
I have SSRS report, in that i have 2 columns like Account_Code , Variance_Column.
i wants to write expression like
if Account_Code starts with 4 then i need to multiply variance_column * 1
if Account_Code starts with 5 ,6 then i need to multiply variance_column * -1
else Same values should appear.
Please do need full.
bala krishnaHi bala,
After testing the issue in my environment, we can use InStr function to achieve your requirement. The following expression is for your reference:
=iif(InStr(Fields!Account_Code.Value,"4")=1,Fields!Variance_Column.Value*1,iif(InStr(Fields!Account_Code.Value,"5")=1 or InStr(Fields!Account_Code.Value,"6")=1 ,Fields!Variance_Column.Value*(-1),Fields!Account_Code.Value))
For more information about InStr function, please see:
http://msdn.microsoft.com/en-IN/library/ms157328.aspx#VisualBasicFunctions
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Pass function name as parameter in SSRS expression
I have a function (GetColumnFieldName) which returns string datatype
Now I want to use this function in below SSRS expression
=Code.GetDisplay("FirstName",Parameters!SelectedCols.Value,Parameters!DisplayCols.Value)
At the above expression I want to replace "FirstName" with function GetColumnFieldName which returns the same "FirstName".
Please suggest.Hi Jajatibabu,
If I understand correctly, you want to use GetColumnFieldName function which returns a field name to replace the “FirstName” in the expression you post.
If in this scenario, we can directly use Code.GetColumnFieldName(parameters) to replace the “FirstName” like below:
=Code.GetDisplay(Code.GetColumnFieldName(parameters),Parameters!SelectedCols.Value,Parameters!DisplayCols.Value)
Note that we should type the correct parameters in the GetColumnFieldName function.
If there are any misunderstanding, please elaborate the issue for further investigation.
Thanks,
Katherine Xiong
If you have any feedback on our support, please click
here.
Katherine Xiong
TechNet Community Support -
Hi All,
Below is the my table with SSRS expressions marked as A and B
Expression A gets the serial number 1, 2, 3 etc
I need to get expression A/B
Any help on this much appreciated
Thanks
Pradnya07It's look like you want B/A, not A/B.
You can try couple things. If you are allowed to use ReportItems and refer to the textbox value, then simply use this:
=ReportItems!textboxnameforB.Value / ReportItems!textboxnameforA.Value
If that gives you error as far as not allow to use ReportItems, then try create a divide function in custom code and then pass the value to it.
Public Function Divide(Num1 as double, Num2 as double) AS double
IF IsNothing(Num1) Or IsNothing(Num2) Or Num1 = 0 Or Num2 = 0 Then
Divide = 0
ELSE
Divide = Num1 / Num2
END IF
End Function
Then, simply use this in the textbox you want the value:
=code.Divide(RunningValue(Fields!new_programmeoutputid.Value,CoutDistinct, "new_outputs"),RunningValue(Fields!new_claimmonthid.Value,CountDistinct,
Nothing))
If that still does not work, then try to bring these values in the query itself.
good luck. -
Hi,
Can anyone tell me how to use OR in an SSRS expression?
I would like to set the BorderStyle Left (& Right) property to "None" for two rows so I need to
use an OR (6 or 9)
This is what I have so far:
=IIf(RowNumber(nothing)=6,"None","Default")Hi,
Try Below,
=Switch(RowNumber(nothing)=6 ,"None",RowNumber(nothing)=9,"None")
OR
=IIf(RowNumber(nothing)=6 OR RowNumber(nothing)=9,"None","Default")
OR
=IIf(RowNumber(nothing)=6,"NONE",IIf(RowNumber(nothing)=9,"NONE","Default"))
Thanks -
Hi,
I am unable to convert the below ssrs expression to sql query. can you guys help.
-- IIF(Parameters!parameter1.Value Is Nothing,
-- " 3>2 ",
-- "column1 NOT LIKE
-- Replace(IIF(Left(Parameters!parameter1.Value, 1) = "'",
-- Parameters!parameter1.Value,
-- "'" & Replace(Parameters!parameter1.Value, "'", "''") "'"),
Thanks.Thank you for your response Carnegie,
I actually have two stored procedures as below. (columns and joined tables are excluded)
I need to change the dates of @DateFrom and @DateTo parameter, I am passing @DateFrom_FD and @DateTo_LD as well.
CREATE ROCEDURE [dbo].[Test]
(@DateFrom
SMALLDATETIME
, @DateTo
SMALLDATETIME
, @program
VARCHAR(MAX))
AS
DECLARE
@DateFrom_FD
SMALLDATETIME
, @DateTo_LD
SMALLDATETIME
SET @DateFrom_FD = DATEADD(MONTH,DATEDIFF(MONTH,0,@DateFrom),0)
SET @DateTo_LD = DATEADD(DAY,-1,DATEADD(MONTH,DATEDIFF(MONTH,0,@DateTo)+1,0))
SELECT
DimDate.[Year]
, DimDate.[Month]
, DimDate.PK_Date
, CustomerID
FROM DimDate
WHERE DimDate.PK_Date BETWEEN @DateFrom_FD AND @DateTo_LD
Now I am using one of the SP as a main report and the other SP as a subreport.
In order to configure the main report and the subreport, I believe that I need to link them with parameters.
However, in the parameters of subreport properties, the option given are only @DateFrom and @DateTo.
No @DateFrom_FD AND @DateTo_LD
Therefore, I am thinking to use expressions to convert @DateFrom and @DateTo the same way I did in SQL.
I am not sure if this works....but this is the only thing that I could think of.
Thank you,
YJB5151 -
SSRS expression for grouping minutes
Hi All,
Can you please help me to write an SSRS expression to group minutes
=SWITCH(
Fields!TotalHours.Value = 0
and 240,
"0 To 4 hrs",
Fields!TotalHours.Value = 241
and480,
"5 To 8 hrs",
Fields!TotalHours.Value = 481
and720,
"9 To 12 hrs",
Fields!TotalHours.Value = 721
and960 ,
"13 To 16 hrs",
Fields!TotalHours.Value = 961
and1200,
"17 To 20 hrs",
Fields!TotalHours.Value = 1201
and12000000,
"More than 20 hrs"
Any help much appreciated
Thanks
Pradnya07Try this...
= SWITCH ( Fields!TotalHours.Value <= 240, "0 to 4 Hrs",
Fields!TotalHours.Value <= 480, "5 to 8 Hrs",
Fields!TotalHours.Value <= 720, "9 to 12 Hrs",
Fields!TotalHours.Value <= 960, "13 to 16 Hrs",
Fields!TotalHours.Value <= 1200, "17 to 20 Hrs",
Fields!TotalHours.Value > 1200, "More than 20 Hrs") -
Hi all,
I am facing some issue with ssrs expression.
I used below expression to show sum of budget.
=Sum( CDbl(Fields!Budget.Value))
When I preview the report it shows #Error in that textbox.
Please help me to fix this one , I am not getting where its breaking..
Thanks
RohitHi Rohit,
According to your description, you want to sum the [EstimatedCostField] with an expression.
In your scenario, since the [EstimatedCostField] is budget which you want to perform sum calculation, you should specify the sum expression like below:
=Sum(CDbl(Fields!EstimatedCostField.Value))
If issue persists, please run the report in the BIDS then check the warning message in output to see the detail information about the #Error. Besides, please also share the report design for our analysis.
If you have any question, please feel free to ask.
Best regards,
Qiuyun Yu
Qiuyun Yu
TechNet Community Support -
SSRS 2005 - Split multiline address field into multiple address columns
Hi all
I have an address field called SiteAddress, which is multiline with carriage returns, and stores addresses as:
SiteAddresss
SiteABC
1 Main Street
Withington
Manchester
M20 1FT
How do I split this address field across multiple new fields, eg:
SiteName AddressLine1 AddressLine2 AddressLine3 AddressLine4 Postcode
SiteABS 1 Main Street Withington Manchester
M20 1FT
Thanks for all help
NazIt is simple using TSQL, refer below example,
;with cte as (
select 'site name' [address]
union
select 'address line 1' [address]
union
select 'address line 2' [address]
union
select 'address line 3' [address]
select * from (select [address], row_number() over (order by address desc) rn from cte) x
pivot
(max([address]) for rn in ([1],[2],[3],[4])) pvt
However if you need in SSRS itself, you can try using custom code to split the address string by char(10) or char(13) and then insert into an array. If the input parameter is 1 return the first address from the array, 2 return the second address and so on.
Custom code can be called from the textbox expression as,
=code.getAddress(Fields!Address, 1)
Regards, RSingh -
Hello,
Is there anyway to default to the first day of the month in a SSRS expression. I'm looking to do the reverse of the EOMONTH() function.
The date value is coming from a parameter @BegDate and formatted YYYY-MM-DD. So if the parameter is set to 2015-08-31 it would show 2015-08-01
Any information would be greatly appreciated.
xI ended up using the following:
DateSerial(Year(Parameters!BegDate.Value), Month(Parameters!BegDate.Value), 1
x -
How Get last five quarters data using ssrs expression
Hi All,
i have an ssrs report where i have to get last five quarters data and also last five months data when i select quarterly/monthly parameter.....
is there any possibilty that we can get this using ssrs expression
any help please.........Hi Mr.SMK,
According to your description, there is an SSRS report, you want to create a parameter, when you select quarterly, data of last five quarters will be displayed. If you select monthly, data of last five months will be displayed. If that is the case, please
refer to the following steps:
1. In design surface, in Report Data pane, right-click Parameters and click Add Parameter.
2. Type parameter name and prompt, set Data Type to Date/Time.
3. Click Available Values in left pane, select Specify values.
4. Click Add button, in Label text box, type Quarterly, then click (fx) button and type the expression like below:
=DateAdd("q",-5,Today())
5. Click Add button, in Label text box, type Monthly, then click (fx) button and type the expression like below:
=DateAdd("m",-5,Today())
6. Right-click the dataset used to retrieve data for the report and open Dataset Properties dialog box.
7. Click Filters in left pane, click Add button, select Data from Expression drop down list, set Operator to >=, in Value text box, type [@ParameterName].
The following screenshots are for your reference:
If you have any more questions, please feel free to ask.
Thanks,
Wendy Fu
Wendy Fu
TechNet Community Support
Maybe you are looking for
-
Why does a particular iCal calendar appear on Mac but not iPad?
I use several calendars within the iCal application ( personal, business, etc.) All of those calendars sync between my Mac and iPad just fine, except one,... it's a football schedule i named 'Buckeye.' All my calendars, including Buckeye, appear in t
-
The window size of Photoshop (or any other) application?
Hi! Is there a way to retrieve the size of the Photoshop (or any other Host) window? (On Mac it seems to be the whole screen?) I didn't find it in documentation Thank you!
-
StateFul SessionBean Passivation
I am running a EJB application in weblogic, using StateFul SessionBean.Suppose say, the maximum number of clients at a time is 100.(And assume that this is the maximum no of beans taht are created).Now 2 more clients 101,102 are coming.This time the
-
my phone was not worked for last two days it happen after the instalation of new os,this is happen one of my friiends also plssssss find some solution
-
How to Install/Access HANA Academy Workshop Exercise Solutions and Templates
In Thomas Jung's HANA Academy tutorial on "Native Development Workshop", solutions and templates are cited in the "Simple "Hello World"" video... HANA Academy - HANA Native Development Workshop: Simple "Hello World" - YouTube Where are ther