Lets say I have two text boxes on a form. the first returns a count value from a SQL statement, or a domain aggregate expression, etc. the second does the same with additional parameters.
Now i want to have another text box (#3) that divides one by the other for a very simple percentage. like this for a controlsource:
=[textbox2]/[textbox1]
this works great unless the original counted value returned is a zero. If the first returned value is a zero, then the second is going to be a zero too, and ideally 0 / 0 should come out to zero, but I get a #Num! error string in the text box.
I realize this is yet another weird request but this is for a dashboard form that has about 50 of these, and they work great, unless I hit a zero.
So is there any way I can set text box properties that i may be unaware of, for this to work without having to write numerous If statements in the code?
Thanks!
I cannot see how you can avoid an if statement when divide by zero is a possibility
=IIf(TextBox1<>0, TextBox2/TextBox1,"N/A")
Mathematically, the division by 0 is undetermined, but for your purposes, you can calculate it with:
=IIf([textbox1]<>0;[textbox2]/[textbox1];IIf([textbox2]=0;0;"N/A"))
This is, when textbox1 equals 0, you check whether or not textbox2 equals 0. If this is the case, then return 0, which is what you want.
Related
I am creating a report, the purpose of which is to print a letter to many different people. Obviously each person's name, email, etc. will be different. For this I am using a list, which I understand uses a tablix.
Now inside each letter I also need some global data that comes from a dataset. For example, the company email, telephone number, etc. This data will be the same for every letter. However, every time I try to use some expression to get this, I get an error such as:
The Value expression for the text box ‘Textbox11’ refers to the
field ‘URL’. Report item expressions can only refer to fields within
the current dataset scope or, if inside an aggregate, the specified
dataset scope. Letters in the names of fields must use the correct
case.
The expression I'm using to get the above error is
=LookupSet(true, true, Fields!URL, "SystemVars")
I've tried other things but I can't figure out what I need to make it word.
Is there an expression I can use to solve this problem? If not, what steps should I take to get my letters working?
You are missing the ".Value" portion in the expression. Try this:
=First(Fields!URL.Value, "SystemVars")
I created a MS Access database for tracking some items at work. Users enter data which is then aggregated in queries (using count or sum) to calculate the actual value for each area, joined using UNION, then compared to goals for that area. I attempted to enter an IIF statement to conditionally calculate the percentage of [Act]/[Goal], leaving it zero if [Act] is blank or 1 if [Act] is greater than [Goal] so there is nothing over 100%. The issue is that it works most of the time, but other times fails with no obvious logic error or reason why that I can figure out.
Sometimes it can't tell that [Act] > [Goal] even though looking at it, it's obvious. The numbers are all integers, nothing crazy or formatting differences. The formula in [Met] is what I hope to achieve. I added the [TEST] field to trace back where it might not be working, which shows Access just isn't always returning the correct answer to [Act] > [Goal].
My Query:
What comes out (just the broken part):
As you can see, it works correctly for most rows, but then thinks 149 is less than 52, and 128 is less than 3. Because of this, it generates [Met] values over 100%.
Has anyone had this happen before or have any suggestions? I have tried using refresh, clicking in the cell to hit enter, everything I can think of.
I think that although your columns are Ints, they are being converted to strings in the variables (or at least one of the variables) Goal and Met.
If you look at the data, you'll see that if you compare them the results of Test are correct for a string comparison.
E.g. "3" > "128" (Because the first character has a higher char value).
In your query, try surrounding the variables with Val() when you are comparing them, as follows:
IIf(IsNull([Act]),0,IIf(Val([Act])>Val([Goal]),1,Round([Act]/[Goal],2)))
This is probably a beginner question and I am missing something fundamental, but I appreciate anyone's time and effort.
I have inherited an Access database, where the data is kept in a separate file to the forms and reports.
A report is used to create a letter to summarise a set of results.
The relevant part is in the Detail section of the report, where pairs of Text Box controls are used to show the name of the test, and the result.
The behaviour of the text boxes is that they are hidden (including the name of the test) when the value is zero in the database. However, sometimes we need to include a zero value.
Is this default behaviour?
I have inspected the VBA project and cannot find any logic that is hiding the text boxes.
Other information:
The field is set up as Number (double)
The default value for the field has been made empty, not 0 which seems to be the default.
I have tried using the format property for the control using #;#;0;"" as described here (http://www.experts-exchange.com/questions/21525364/Show-zero-values-as-dashes-on-an-Access-report.html)
I have also tried using ControlSource =IIF([fieldvalue]>0,[fieldvalue],"0") which did show a zero, but the descriptor text box still disappeared, and it was appearing as 0 whether the database field value was 0 or nothing.
Please let me know of any other details that would be helpful.
Thank you everyone for your help.
I hadn't traced back for enough in the logic chain, which #KenWhite's answer gave me the hint for.
The issue was in the query underlying the report - the logic for the field had conditional parameters on it, using IIf() and NULL / 0 checks.
So, I have a problem in Report Builder that is just driving me absolutely crazy.
I have two dataset; one called DS_Grades and the other DS_Pupils. I want to do a simple LookUp based on PupilID, a field that is in both datasets, and return a grade from DS_Grades into a Matrix based on DS_Pupils.
The formula I am using is:
=LookUp(Fields!PupilID.Value, Fields!PupilID.Value, Fields!Grade.Value, "DS_Grades")
I have confirmed that:
1) DS_Grades has the right PupilIds
2) There are actually values in the Grades field
3) Both PupilID fields (I.E. in both datasets) are definitely Integers and not text.
Moreover, if I add a calculated field to DS_Grades called "test" and populated with the value 208301, which is a valid PupilID, then I can enter the below formula and it works fine:
=LookUp(208301, Fields!test.Value, Fields!Grade.Value, "DS_Grades")
So, the LookUp itself must be matching properly, which means that the PupilID fields must be causing the problem, but I have quintuple freaking checked them and they definitely have the right values, in the right format. I am at a total loss as to why SSRS thinks that they don't match.
Help please!
Got it! Some filtering was at Dataset Level (instead of query where I normally do it) that was throwing the whole thing out of joint. Removed that, and it's fine.
I have two equations on the same dataset. One returns an error, the other does not. The equations are as follows:
1) =Sum(IIF(Fields!Service.Value="Dispatch Only", 0, Fields!Charge.Value))
2) =Sum(IIF(Fields!Service.Value="DispatchOnly", 0, Fields!Charge.Value))
Note that the only difference between the two is the fact that I took a space out of the field I'm looking for.
I want a total sum of the entire data set. But then I also need to know what that same sum is, without the "Dispatch Only" values. Obviously, equation #2 doesn't produce any useful information (it's just the sum again), but I added it just to prove I wasn't insane with some very basic typo, like a comma out of place.
What am I doing wrong with equation #1??
This commonly occurs when applying an aggregate on differing data types, which you're unlikely to get unless you have an IIf statement, like in your example.
You're probably getting a mismatch between Charge and 0 (i.e. between the underlying data type of Charge and the integer 0).
To get around this, make sure that 0 is the same data type as Charge, i.e. use something like CDec(0) or CDbl(0) as required.
One other option to consider is to use Nothing in place of 0 - by using the SSRS null value you avoid any data type clashes, but it does have the disadvantage of returning Nothing if there are no matching Dispatch Only rows.