Microsoft Access if statement with two possible filter - ms-access

I want to filter according to selection but what I'm trying to do is that if Q1 and Q2 option selected I want to filter them for both Q1 and Q2. Here is code I wrote and not working:
Like IIf([Forms]![Form1]![Combo1]="All";"Q1" Or "Q2";[Forms]![Form1]![Combo1])
After running this code, program changes "Q1" Or "Q2" part to ([QQuery].[Q])="Q1" Or ([Q_Query].[Q])="Q2".
I'm already able to filter one by one, I mean for Q1, for Q2 or for Q3 seperately. How can I filter, for Q1 and Q2 at the same time. Thanks.

OK, I finally did it! This what I wrote:
IIf([Forms]![Form1]![Combo1]="Q1+Q2";"Q1"; [Forms]![Form1]![Combo1]) Or IIf([Forms]![Form1]![Combo1]="Q1+Q2";"Q2";[Forms]![Form1]![Combo1])
and so on. but if you want to add All part, you have to add to the end of codes above:
Or Like IIf([Forms]![Form1]![Combo1]="All";"*";[Forms]![Form1]![Combo1])
Hope this helps other people having same problem Thanks again Linger :)

You are not specifying a wild card so you are not actually using LIKE and the result would be the same as if you used equality operator (=).
I do believe the below will work better for you. Replace Quarter with the actual field name. I put them in parentheses just in case you have any other criteria you are adding to the WHERE clause.
IIf([Forms]![Form1]![Combo1]="All"; "(Quarter = 'Q1' Or Quarter = 'Q2')";[Forms]![Form1]![Combo1])
If you truly need to use LIKE then it should look something like the following:
IIf([Forms]![Form1]![Combo1]="All";"(Quarter LIKE '*Q1*' Or Quarter LIKE '*Q2*')";[Forms]![Form1]![Combo1])

Related

SSRS - Expression with Lookup in child group causes repeating label values

I created a matrix with two column groups (year and quarter).
The expression for the quarter label (the expression under [year]) is:
"Q " & CStr(Fields!quarter.Value)
So in the report I get Q1, Q2, Q3 and Q4 as quarter labels.
We have a international team so I need the others labels to be in german or in english, depending on the user. So I created a dataset with all translations which is filled from a translation table in the database. To get the correct translation for the label I use the LOOKUP() function.
When I use LOOKUP() to get the correct translation for the "amount Rest" textbox (located in the year group) it works fine:
=LOOKUP(11, Fields!ID.Value, Fields!description.Value, "ds_Labels")
The result:
But when I try to use LOOKUP() to get the translation for the "amount" textbox, which is located in the quarter group, the correct translation appears but the year label also starts with 2014 instead of 2008 and the quarter and year labels repeat:
=LOOKUP(17, Fields!ID.Value, Fields!description.Value, "ds_Labels")
The result:
I've no idea what kind of bug this is and how I can get rid of it. Maybe someone can help me :)
UPDATE
Like I mentioned in the comments, the LOOKUP() function works in the first three columns of the quarter group. The report goes crazy if I try to use LOOKUP() in the fourth textbox of the quarter group (see the second last screenshot). But I still don't understand why...
UPDATE 2
When I deploy the report on a SSRS 2008R2 the report works completely fine. But I need it to run on SSRS 2012. Maybe it is a SSRS2012 bug?
Have you made sure that only one record is being returned when you look up the record(s) associated with id 17? The function is designed to be used for 1 -to- 1 relationships
I believe it's a bug. Running Lookup() / LookupSet() queries against the same dataset that is being currently rendered in a tablix causes duplicates.
The only workaround I found is to pass a copy of the dataset and run Lookup() queries against that copy. This way everything works fine.

SSRS: how to group by multiple parameters

I need to create a report using SSRS, it needs dynamicly group by the matrix.
I added a parameter(name: ColumnData) for it and the available value like 'Date', 'Type', 'ServerName',
for a single value, I can edit the group by expression to
=Fields(Parameter!ColumnData.Value).Value
but when the parameter is multiple, Parameter!ColumnData.Value would return a list and I need to use like that:
==Fields(Parameter!ColumnData.Value(0)).Value & Fields(Parameter!ColumnData.Value(1)).Value
but it's not what I want as I need to indicate the index manually...
Anyone knows how to use the multiple parameters in the group by expression?
Thanks a lot!
If you deselect 'Allow multiple values' in the Parameter properties, your group by expression should work as is.
You will then be able to group by the selected value from the parameter.
(It will then not be possible to choose more than one of the values).
But it only makes sense to group on one value, or?
I stumbled on this topic, but my solution was simple. I had to group by multiply fields, and ended using something like this:
<GroupExpression>=Fields!ColumnName1.Value</GroupExpression>
<GroupExpression>=Fields!ColumnName2.Value</GroupExpression>
<GroupExpression>=Fields!ColumnName3.Value</GroupExpression>
But this may not be what you are looking for since you wanted something more generic.
You can check this answer as it has some advices about matrix:
Multiple group expressions in list (ssrs 2005)
Hope that helps.

Fuzzy Logic sorting

Starting off, I apologize for bad table structure, it was not my decision and existed before me.
Anyway, I have a table tbl_cities that is a list of, you guessed it, cities (but for whatever reason are stored in column [desc]). I wanted to make a nifty AJAX text input that, as you type, it tries to find out what cities you are typing and offer them as suggestions. It's kinda like this example. So my query looked like this
SELECT [desc] FROM tbl_cities WHERE [desc] LIKE 'phil%'
Which works fine. However, I see there are a bunch of misspellings in this table, so I want to add fuzzy logic. I want to keep getting cities that match the first letters they type, so I have this query.
SELECT [desc] FROM tbl_cities WHERE [desc] LIKE 'phil%'
OR DIFFERENCE('phil', [desc])>3
Now I want to sort based on the [desc] LIKE 'phil%' before the fuzzy logic part. So in this example, Philadelphia should appear before random cities like PAOLA and POWELL
I would try something like that :
order by case when [desc] like 'phil%' then 0 else 1 end, [desc]

Access 2007 - Using results of an equation inside another equation on a report

I inserted three text boxes to test how this could work:
Text81: =1
Text82: =2
Text83: I want this one to be the sum of Text81 and Text82
Thanks in advance for your help on what I think is a pretty simple problem.
There are a couple options that spring to mind.
First you could always modify the data source for the report to include the calculated field.
Second, which is what your question drives at, you can do something like this:
=[Text81] + [Text82]
Should work when typed into the Control Source of a TextBox provided Text81 and Text82 are the data field names from the Data Source of the Report. If they are not you would put the corresponding data field names in the square brackets []
Hope this helps

In Access VBA expression builder, how do I sum a column conditionally?

Let's say I have two fields A and B and one textbox B_input. I would like to set up a query so it sums all entries of column A where B = B_input
Currently I have:
==Sum(IIf([B_input]<>"All",[A],IIf([B_input]<>[B],0,[A])))
I did more testing, it seem the problem is that under Sum(IIF([B_input])), it's not recognizing the value of [B_input], but if I just have IIF([B_input]), it recognize the value just fine, any ideas?
iif([B_input]=="xyz",Sum[A],False)
Might be what you're after but I'm not sure i understood your question properly.
Alternatively, just edit the sql to something like
SELECT(SUM[A]) AS SumOfA FROM [MyTable] HAVING ("B"="xyz");
How about:
=Sum(IIf([B_input]<>"All",[A],0))
Gave up, went with form filtering instead.