Combining && and || filters

if there’s a solution somewhere else in the forums, I can’t find it. Feel free to point me to it.

I have a date slider that sets a display to MM/YYYY format. I have a repeater with a list of dates in MM/DD/YYYY format.

I’m using the slider to filter the Repeater dates and I’m getting 90% of what I need, but the last part eludes me and I’m sure it has something to do with the way I’m constructing the filters.

because the slider covers multiple years I need the following to happen:

My slider goes from 01/2016 to 12/2018.
For the “end date” value I used the following format for my filter:
[[(RPMonth <= SliderMonth && RPYear = SliderYear) || (RPMonth > SliderMonth && RPYear < SliderYear)]]

When I set the slider to 06/2017, the filter takes out ALL months with a value less than 06, no matter the year - meaning months 07/16-12/16 are being filtered out.

I know I must be missing something. What am i doing wrong?

Okay I’ve narrowed it down to the second part of the filter - the first part - [[RPMonth <= SliderMonth && RPYear = SliderYear]] fine by itself, but the second part - [[RPMonth > SliderMonth && RPYear < SliderYear]] - does NOT work by itself.

At first glance I can’t really tell you anything without seeing how your file works, but I can give you this advice:

Take your filter expression and translate it into plain English (or whatever your native tongue may be otherwise). Finding the fault in the logic you’ve written is easier when you’re evaluating it as a written statement as opposed to one intended for a program.

This works the other way too: write out how you want it to work as if you were instructing someone, then piece by piece translate that into the logical expression for the program.

Finally I see that the basic structure of your statement is:

If A and B, or C and D.

If A and B are true then the whole expression is true regardless of whether C or D are true. Is this what you want?

I’ve done that, I’ve also double(and triple)-checked my syntax, looked for missing parentheses, missing/extra spaces, periods instead of commas, etc. I’ve also used the set text option to display the text based on the conditions of the filter case to make sure the conditions are pulling the correct info (they are).

Basically, if I set the end date on my slider to 06/2017, I want all the months in 2016 to display in addition to the first six months of 2017. So, I have the “slider date” and the “repeater date.”
So if the month on the Repeater is greater than the month on the slider ( 07 through 12) and the year on the repeater is less than the year on the slider (2016) all those months should display, but they’re not.

I think I see the issue, it’s a common one.

Use == not =

See if that works. Axure uses JS syntax and == is equality while = is variable assignment. But without a file to poke at I can only make guesses.

I don’t use == anywhere; I’ve got one <= and the rest are < or >. What’s hanging me up is that I have two pairs of criteria and I want to filter on either of them. The file is huge (and kind of a mess right now, or I’d post it), but what I want to do is apply a filter like this:

x < a and y <= b OR x > a and y < b

Okay, I pulled out the key elements and stripped this down to the basic issue. If you open the attached RP, you will see conditions and filters on the submit button. To keep it simple, I only included one case, and it’s tied to the “To” field. If I can solve this one issue, it will solve them all.Filter Problem.rp (63.6 KB)

I’ll take a look at your file, but this is what you posted earlier:

[[(RPMonth <= SliderMonth && RPYear = SliderYear) || (RPMonth > SliderMonth && RPYear < SliderYear)]]

You have RPYear = SliderYear. It should be RPYear == SliderYear

Whoops! That was a typo!

At the simplest, and it looks as if you’ve done, it would be:

(x < a && y <= b) || (x > a && y < b)

The problem is I can’t find a filter that looks like that in your example file, so it’s hard for me to say. One thing I might suggest is store day, month, and year in separate columns in your repeater. At least that way there’s less string parsing to do and less room for errors.

If the expression still isn’t working I’d start looking at the variables you’re passing in there and make sure they are what you expect them to be. There’s nothing obviously wrong with your boolean expression.

Oh, should have clarified, sorry. The first half of my double filter worked fine; it was only the second half that was giving me problems, so that’s the filter I included in the rp I uploaded. It’s on the submit button. It’s not working by itself. So my goal is to get that part working and then try joining it back to the first half with the ||

Ok. Not on my computer but analyzing the expression you might be having trouble with the second half. You’re using substr which takes the start index and the number of following characters. So you’re comparing the 10 characters following the character in the 9th position (remember 0 indexed) of one value to the 7 characters following the 6th character of the other value.

Perhaps you meant to use substring() which takes the start and end index instead. Or instead change the second argument to 2 if you only want the 2 characters following that index.

Hmmm, interesting, as substr has been working correctly for me elsewhere - I tested it by displaying the substr values in a box, just to make sure because I’m always unsure of exactly which numbers to use. I will try substring and see if it makes a difference. I’ll try anything at this point!

I have a hard time imagining the second part of your expression ever evaluating to true, which means the whole expression will always be false.

Next debugging tip I’d try is have four set text actions on widgets that output each variable you’re using in the expression and compare manually to see if you’re getting the values you think you’re comparing.

I replaced substr with substring and I’m getting the exact same results. Tried with slice and got the same results. ARGHFilter Problem 3 ways.rp (112.1 KB)


Since you are dealing with dates, you’re much better off using the Date functions. I updated your dataset to have real dates - i.e., with four-digit years - though it just displays two-digit years in case that’s what you want.

In the filter, all dates are converted to milliseconds, so >= and <= work out nicely.

The leading zero on the month in the filter entries is not required.

Filter Problem 3 ways.rp (65.1 KB)

[ Edit ] As true to form, I found an error AFTER I posted. Sigh. Change the expression that creates the last millisecond of the end date to this:

[[ (todate.substr(0,todate.indexOf("/"))+"/01/"+todate.slice(-4)).addMonths(1).addMilliseconds(-1).valueOf()]]

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.