0

Compound filter for a view

Hi All,

I would like to do a compound filter in a view by using a date range and a dynamic multiple choice. That way I can filter for one or more customer sales within a given date range.

here is the code for the date range placed in the view formula field:

what can I add to this code to use the dynamic multiple choice field for customers?

let xStart := 'StartDate';
let xEnd := 'endDate';
select SALES where 'Sale Date' >= xStart and 'Sale Date' <= xEnd

Thanks for looking!

Sam

30 replies

null
    • Fred
    • 4 mths ago
    • Reported - view

    Is Customers a N:1 reference field in Sales? You can only select 1 customer for each Sales records?

      • Sam.1
      • 4 mths ago
      • Reported - view

      yes

    • Fred
    • 4 mths ago
    • Reported - view

    Maybe something like:

    do as server
        let t := this;
        select Sales
            where 'Sale Date' >= t.'StartDate' and 'Sale Date' <= t.'endDate' and
            (var c := Customers;
                count(numbers(t.Customer)[= c]) > 0)
    end
    do as server
        let t := this;
        let getSales := (select Sales);
        getSales['Sale Date' >= t.'StartDate' and 'Sale Date' <= t.'endDate' and
            (var c := Customers;
                count(numbers(t.Customer)[= c]) > 0)]
    end
    

    I put in two different ways cause I saw some lag in my test DB of only 16 records and I don't know how many Sales records you have.  So try either lines 1 - 7 or 8 - 14 and see which is faster.

      • Sam.1
      • 4 mths ago
      • Reported - view

       thanks Fred!! I’ll plug it in and then give you an update.

      • Sam.1
      • 4 mths ago
      • Reported - view

      Fred Thank you Fred! You are spot on with the second one.

      I am able to search for a product purchased within a given date range by using another dMC field for products. 

      Do you think it is possible to filter for both at the same time? 

      such as trying to search/filter within a given date range to see if--- a chosen customer or customers have purchased a chosen Product or Products?

      • Sam.1
      • 4 mths ago
      • Reported - view

       Hi Fred,

      How would this read if using the reference field searching through the products table. I would be searching for just one product. With the dMC there are too many to easily search with the combo box or radio buttons.

      • Fred
      • 4 mths ago
      • Reported - view

      Sorry, I thought I replied, but obviously I haven't. I'll get to something tomorrow (Dec 18) morning (PST). A reference field is a fine choice. I'm guessing you don't want to have to fill in all the search options. Especially Product. If Product is empty then it should show all Customer.

    • Fred
    • 4 mths ago
    • Reported - view
     said:
    You are spot on with the second one.

     They both do the same thing. Is the 2nd one faster?

      • Sam.1
      • 4 mths ago
      • Reported - view

       the second one is very fast. I did not try the first. I will do the first and update you

      • Sam.1
      • 4 mths ago
      • Reported - view

      both the same speed Fred. 250 records. 

    • Fred
    • 4 mths ago
    • Reported - view
     said:
    I am able to search for a product purchased within a given date range by using another dMC field for products. 
    Do you think it is possible to filter for both at the same time? 
    such as trying to search/filter within a given date range to see if--- a chosen customer or customers have purchased a chosen Product or Products?

     Most things are possible in Ninox. Adding another dMC brings up the question do you want the filtering to happen even if no product is selected? I have set it up to take into account an unused Product selection. Please make sure that all the field names match yours. This is on my DB. The big thing to change is line 8 where we set variable "p". You need to trace your path from Sales to Products properly.

    do as server
        let t := this;
        let getSales := (select Sales);
        if Products then
            getSales[Date >= t.'Start Date' and Date <= t.'End Date' and
                    (var c := Customers;
                        count(numbers(t.Customer)[= c]) > 0) and
                (var p := OrderItems.catalogItems.Products;
                    count(p[var subp := this;
                                count(numbers(t.Products)[= subp]) > 0]) > 0)]
        else
            getSales[Date >= t.'Start Date' and Date <= t.'End Date' and
                (var c := Customers;
                    count(numbers(t.Customer)[= c]) > 0)]
        end
    end
    

    I created a dMC called Products that points to my Products table and lists all Products. But if you want only products that the Client has bought then you can use the record() command in a for loop to get the records selected from Customer then build a list of products.

    Lines 8 - 10 is the new part. We have to use two counts because when you trace the relationship from Sales to your Products you will get an array of items, so we need to add a second level of counts.

      • Sam.1
      • 4 mths ago
      • Reported - view

       Thank you Fred! Is this Database of yours that you are referring to a small one made to work through this formula?

      If so, Could you kindly attach it to a reply so that I have something to follow.

      Thanks Again,

      Sam

      • Fred
      • 4 mths ago
      • Reported - view

       I would love to but MacOS app 3.10.10 broke the export function and I don’t have a Pro account.

      What questions do you have?

      • Sam.1
      • 4 mths ago
      • Reported - view

      Fred Not at the moment. I just got around to for a few minutes.

      I will give it another try later and update you.

      Thanks for everything,

      I do not have the pro. The starter allows me to export to iCloud ( or Dropbox) on my iPhone or iPad ( when signed in I can see all of my databases on both the phone and iPad). The iPhone will not see all of the databases if using the Legacy for iPhone).Then I upload from  iCloud and Pull it from the download folder.... after downloading the upload.

       

      Sam

      • Sam.1
      • 4 mths ago
      • Reported - view

      I edited the last message.

      • Fred
      • 4 mths ago
      • Reported - view

      You must not have updated your app to 3.10.10. If so then DO NOT UPDATE. 3.10.10 breaks the export. I just tried on my iPhone and it does not work.

      • Rafael Sanchis
      • Rafael_Sanchis
      • 4 mths ago
      • Reported - view

       Hi Fred on 3.10.8 is break the export too.

      • Sam.1
      • 4 mths ago
      • Reported - view

       I spoke too soon....same here

      • Sam.1
      • 4 mths ago
      • Reported - view

        Hi Fred, I was able to export from my Mac. Not yet on the iPad as it is still 3.10.10.

      The mac indicates a version of 3.10.11.

      when you have a chance, please attach the small database showing how you handled the filter.

      thank you in advance,

      Sam

    • Fred
    • 4 mths ago
    • Reported - view
     said:
    How would this read if using the reference field searching through the products table. I would be searching for just one product. With the dMC there are too many to easily search with the combo box or radio buttons.

    You can try something like:

    do as server
        let t := this;
        let getSales := (select Sales);
        if Products then
            getSales[Date >= t.'Start Date' and Date <= t.'End Date' and
                    (var c := Customers;
                        count(numbers(t.Customer)[= c]) > 0) and
                (var p := OrderItems.catalogItems.Products;
                    count(p[= t.Products]) > 0)]
        else
            getSales[Date >= t.'Start Date' and Date <= t.'End Date' and
                (var c := Customers;
                    count(numbers(t.Customer)[= c]) > 0)]
        end
    end
    

    Remember that line 8 has to change to match your Path from Sales to Products.

    This assumes that you use the default reference field name for the Products table. If needed, change to match yours.

    I added the if statement at line 4 to take into account if you leave Products empty or not.

      • Sam.1
      • 4 mths ago
      • Reported - view

       this looks the same as what you kindly sent 3 days ago for the dynamic choice filter selection.

      I'm trying to use the reference TO the products for easily searching the table.

      The list is too long to be looking for a product in a combo box or buttons.

      Can it be done from a reference TO in ninox.

      Also, I sent a ticket to support and they said the 3.10.11 be releasing this week will fix the Export issue

      • Fred
      • 4 mths ago
      • Reported - view

      It does doesn't it. 😉

      But since you have switched to a reference field you don't need to do the multi-count step. So line 8 use to run to line 10 now it stops at line 9.

      Great to hear that they are giving a timeline. Normally, they are mum about that.

      • Sam.1
      • 4 mths ago
      • Reported - view

       I'll plug it in and update you later!

      Thanks

    • Fred
    • 4 mths ago
    • Reported - view
     said:
    when you have a chance, please attach the small database showing how you handled the filter.

    here it is. Open the Quick View then go to the Tab tab.

      • Sam.1
      • 4 mths ago
      • Reported - view

        ok--thanks, will do

Content aside

  • 4 mths agoLast active
  • 30Replies
  • 242Views
  • 3 Following