Is it possible to have 2 custom functions in one cell?
I currently have one function and another function connected through a & symbol. But what ends up happening is that both of them run at the same time, thus producing two results in one cell. I want it to be so that when one is true the other one won't be seen and only the result of one will be showing.
Any help?
Just use IF
=IF(fn1(B1), fn1(B1), "") & IF(fn2(B1), fn2(B1), "")
if fn1() returns false the first part will be an empty string "" otherwise it will be the result. Same for the second part.
IF documentation
Related
I'm trying to concatenate a string on the end of a sum, but if the sum is nothing, it breaks. It seems like this is due to SSRS evaluating both conditions of the IIf statement, but I can't figure out how to get around this.
I've got....
=IIf(IsNothing(Sum(Fields!Work.Value)), "", Sum(Fields!Work.Value).ToString + " J")
Which will print out the work summary + " J" if there is one, and #Error if not. What's the SSRS workaround?
Update / Clarification
The report in question is grouping on dates and then summing up Work, so it's not the case that Work is null, per se, but that for this particular date for this particular user, there are no rows in the group.. So, there are no rows to sum up in the error causing instance.
Sample Data Set
Name Date Work
Andy 12/1/15 511.30
Andy 12/1/15 549.70
Drew 12/2/15 484.80
Drew 12/2/15 322.36
Sample Report (current)
Name 12/1/15 12/2/15
Andy 1061 J #Error
Drew #Error 807.16 J
Sample Report (expected)
Name 12/1/15 12/2/15
Andy 1061 J
Drew 807.16 J
Have you considered doing the two parts of your desired output in two different expressions in the same Cell?
I assume for the current structure you have used a matrix, with Rows for the Name, and Columns for the date. You can the set the Data to be Sum of Work, as shown here, and in the red text in the image below.
=Sum(Fields!Work.Value)
You then then right click the cell and select "Create Placeholder" to insert a second expression in the same cell.
Set the value of this expression to be as shown here, and in the blue text below
=iif(Sum(Fields!Work.Value) > 0, " J", "")
Then when the report is run, it will always show the Sum if there is one, and if the value of the Sum is greater than zero, it will also display the J as required.
Hopefully this is the behaviour you require. Please let me know if you require further assistance with this solution
Try this:
=IIF(SUM(IIF(Isnothing(Fields!Total.Value),0,Fields!Total.Value)) = 0,
"",
SUM(IIF(Isnothing(Fields!Total.Value),0,Fields!Total.Value)).ToString + " J"
)
Let me know if this can help you
IIF does not short-circuit so this #Error is from SSRS trying to use the ToString function on NULLs.
The workaround is to add another IsNothing check in the false section before using ToString:
=IIF(IsNothing(Sum(Fields!Work.Value))
, ""
, IIF(IsNothing(Sum(Fields!Work.Value)), "", Sum(Fields!Work.Value)).ToString & " J")
To solve this exact problem, because if there is no Work to display then the report should display nothing, instead of using the IIf statement with concatenation, it is simple and sufficient to set a conditional visibility on the cell.
In the cell, use the expression:
Sum(Fields!Work.Value).ToString + " J"
Then for the same cell, select:
Text Box Properties > Visibility > Show or hide based on an expression
and enter:
=IsNothing(Sum(Fields!Work.Value))
While this solves this specific problem, if the solution requires the empty cell to display anything other than blank, then the original IIf short-circuit issue is still an issue.
I use the status bar in nearly all my macros . If implemented correctly , allows you to see where your code is at.
E.g
SysCmd(4, "Sorting...")
SysCmd(5)’Set status bar back to normal
Question - How do I get the status bar to display a cell value?
E.g
SysCmd(4, "Sorting...") & xl.("Sheet1").Range("A1")
Above doesn’t work, but is there a way of doing this, in Access VBA ?
When you use 4 (acSysCmdSetStatus) as the first argument to SysCmd, you can include only one additional argument ... so two arguments total, not three.
But you can combine your proposed second and third arguments into one string, and SysCmd will cooperate ...
SysCmd acSysCmdSetStatus, "Sorting... " & xl.("Sheet1").Range("A1")
Note I assumed xl in your cell reference, xl.("Sheet1").Range("A1"), is an Excel workbook object. Since it turns out xl is an application object, Sobigen's suggestion, xl.activeworkbook.sheets("Sheet1").Range("A1"), makes sense to me.
But whatever the correct cell reference is, take that and concatenate it with whatever else you want to appear in the status text ... and use that entire string as the second argument to SysCmd
I have a spreadsheet with roughly 750 part numbers and costs on it. I need to add $2 to each cost (not total the whole column). The range would be something like D1:D628 and I've tried using =SUM but either I'm doing it wrong or it isn't possible.
I initially tried =SUM(D1:D628+2) and got a circular reference warning, I've tried variations of the formula and keep getting errors even after removing the circular reference. I also tried the following VBA module insert:
Sub Add2Formula()
' Add 2
For Each c In Selection
c.Activate
ActiveCell.FormulaR1C1 = "= " & ActiveCell.Formula & "+2"
Next c
End Sub
If you just want to add 2 to a range of numbers (not formulas) then
enter the number 2 in a blank cell somewhere
copy it
Select the cells you want to add 2 to, and then select paste special, choose ADD as the operation option.
The following formula should work
{=SUM(D1:D628+2)}
Leave out the curly braces but press CTRL+SHIFT+ENTER to enter the function (rather than just ENTER)
EDIT: explanation
by pressing CTRL+SHIFT+ENTER excel treats the formula as an array, and loops through each cell individually adding 2 and then summing
I have an RDLC report with a table in it. I want to hide a string column if there is no data present in any of the rows(supress if blank sort of thing). I have been googling for the last 2 hrs and trying with different suggestions but i can not make it work.
I tried the following so far.
Set the expression for the Hidden attribute of the column to
=IIf(Fields!Category.Value = "", True, False)
But it is checking only the first row but not the entire row set.
Trying to create a concatenated string with the field values, so if the final string is empty i'll hide the table column. But i can't find a way of concatenating a string column from a table. Runningtotal() works with only numbers it seems.
Can some one point me to the right direction.
initially i thought it is very easy, but doesn't seem so.
Did you try to use CountDistinct?
I think something like this should do the trick
=(CountDistinct(Fields!Category.Value) > 1) Or (Fields!Category.Value != "")
Or you can try to make a custom string aggregate function
String aggregation in SSRS 2005
Hi All I need your advice,
1) I have a dynamic string which changes each time.
for example today the string will be "ItemA,ItemB,ItemC" and tomorrow it will be "itemA,ItemB" only.
2) I have an SSRS report which has 3 columns
3) I want to split this string "ItemA,ItemB,ItemC" and want to show split substrings in these 3 columns of ssrs table. the Delimiter is "," (comma)
4) I had used
=Split("ItemA,ItemB,ItemC",",").GetValue(0) in the first column of the report
=Split("ItemA,ItemB,ItemC",",").GetValue(1) in the second column of the report
=Split("ItemA,ItemB,ItemC",",").GetValue(2) in the third column of the report
5) everything works fine until my string is "ItemA,ItemB,ItemC" ,
BUT WHEN MY STRING CHANGES TO "ItemA,ItemB" I am seeing "#Error" in the third column.
I understood the error, for
=Split("ItemA,ItemB,ItemC",",").GetValue(2) we don't have any value because the string now has only 2 values after applying split function.
Is there any way i can avoid #Error in the third column.
NOTE: I have to compulsorily use 3 columns in the ssrs report.
I had tried using =Replace(Split("ItemA,ItemB",",").GetValue(2),"#Error","NULL") in the third column but that also wont worked.
This is similar to the divide by zero issue in using IIF statements. The problem is that IIF is not an expression, it is a function with three parameters:
IIF(Condition, ValueIfTrue, ValueIfFalse)
Accordingly, ALL parameters are evaluated BEFORE being passed to the function, which results in the error because the erroneous expression is still evaluated even when the condition should mean that it isn't.
I can't see a way to use the usual workaround tha solves the problem in the divide by zero case. What we need is a real language that doesn't have this problem. Fortunately, this is availble in the form of custom code.
Do the following:
Right-click on an area of the report surface that has no report objects
Select Report Properties
Click on the Code tab
Insert the following code:
Public Function ExtractCode(Combined As String, Position As Integer) As String
if (Split(Combined, ",").Length >= Position) Then
Return Split(Combined, ",").GetValue(Position-1)
Else
Return ""
End If
End Function
Click OK and go back to the report
Right-click on the cell you want the expression in and click Expression
Insert the following expression:
=Code.ExtractCode(Fields!Combo.Value, 3)
The value 3 is the "column" that you want to extract from the Combo field, so to get the second "column" you would use 2. If there isn't a column at that position, an empty string is returned.
you could change the visibility of the 3rd column to hidden if the name returns an error
You can append a dummy element and then split:
yourText = "ItemA,ItemB"
item0 = Split(yourText & ",", ",").GetValue(0)
item1 = Split(yourText & ",", ",").GetValue(1)
item2 = Split(yourText & ",", ",").GetValue(2)
item0 = ItemA
item1 = ItemB
item2 =