cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MH3
Post Prodigy
Post Prodigy

Filter Gallery by Multiple Controls 1 Dropdown, 1 Combo and 1 toggle

Hi, 

I have a Gallery based on SQL DataSource and currently I am filtering the data based on the date selected in the DatePicker Control.

But I want to filter by Customer ComboBox, Project DropDown and a toggle which shows that the task was Billable "true" = Billable tasks or "false" = Not Billable tasks.

I think I am stuck in creating the formula on any of the combinations. 
Filter.jpg

AnyHelp?

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@MH3 
There is one potential problem with you scenario.  You are currently filtering project and customer IF they are selected.  If they are not selected, then they are not included in the filter.

If you use a checkbox or toggle (both pretty much the same), then there is only true or false...there is no ability to "exclude" filtering on the billable.  In other words, if the user decides they want to get results from a date range and a customer but don't care about the project or Billable, then your formula will STILL be filtering on the NO for billable.

 

If that IS an issue, then I would consider instead a Dropdown control (let's call it ddBillable) with Items property of ["Both", "Billable", "Not Billable"]

Then your formula would be:

Sort
    With({_startDate: Value(Text(StartDate.SelectedDate,"[$-en-US]yyyymmdd")),
          _endDate: Value(Text(EndDate.SelectedDate,"[$-en-US]yyyymmdd"))},
      
          Filter(CollectTest1, 
              UserId=MyUserEmail &&
              (
               (IsBlank(StartDate.SelectedDate) || IsBlank(EndDate.SelectedDate)) ||
               (var1 && var2 && DateAsInt >= _startDate && DateAsInt <= _endDate)
              ) &&
              (IsBlank(CustomerCombo.Selected._customerID) || Customer = CustomerCombo.Selected._customerID) &&
              (IsBlank(ProjectCombo.Selected._projectID) || Project = ProjectCombo.Selected._projectID) &&
              (Switch(ddBillable.Selected.Value,
                   "Both", true,
                   "Billable", Billable = 1,
                   Billable = 0
                 )
               )
          )
    ),
    DateAsInt
)
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

13 REPLIES 13
Suchitra1996
Resolver II
Resolver II

@MH3 

 

Hi,

 

You can add && conditions in your filter formula in Items property in the gallery.

 

If(Toggle1.value=true,Filter(DataSource, column1value = combobox.selected.value && column2value = dropdown.selected.value && column3value="Billable"),Filter(DataSource, column1value = combobox.selected.value && column2value = dropdown.selected.value && column3value="NonBillable"))

 

 


--------------------------------------------------------------------------------
If this post helps answer your question, please click on “Accept as Solution” to help other members find it more quickly. If you thought this post was helpful, please give it a Thumbs Up.

Thanks for your reply @Suchitra1996 ,

 

But things are not happening like this.

My Current formula for Gallery item is working on DatePicker and it shows the data based on the date selected.

 

Sort(If(var1&&var2,Filter(CollectTest1,UserId=MyUserEmail),Filter(CollectTest1,UserId=MyUserEmail,(DateAsInt>=Value(Text(StartDate.SelectedDate,"[$-en-US]yyyymmdd")))&&(DateAsInt<=Value(Text(EndDate.SelectedDate,"[$-en-US]yyyymmdd"))))),DateAsInt,Ascending)

 

Now, I want to filter the gallery based on these controls irrespective of the date picker controls.
Like I want to see the List of Tasks of a specific customer which is selected in the combo box,
or a Task which is associated with a Project. etc

MySQL DataSource of Gallery is TimeSheet Table

Which have fields Task,Date, Project ID, Customer ID, Billable (indicator) 1 for True, 0 for false in sql.

 Project Table:  have Id and Descr Fields.

Customer Table: have vc_code (represented as Customer ID in timeSheet Table), vc_name (as Customer Name) and address and etc fields.

@eka24 

RandyHayes
Super User III
Super User III

@MH3 

Please consider changing your Formula to the following:

Sort
    With({_startDate: Value(Text(StartDate.SelectedDate,"[$-en-US]yyyymmdd")),
          _endDate: Value(Text(EndDate.SelectedDate,"[$-en-US]yyyymmdd"))},
      
          Filter(CollectTest1, 
              UserId=MyUserEmail &&
              (var1 && var2 && DateAsInt >= _startDate && DateAsInt <= _endDate) &&
              (IsBlank(customerCombo.Selected.'Customer ID') || 'Customer ID' = customerCombo.Selected.'Customer ID') &&
              (IsBlank(projectCombo.Selected.'Project ID') || 'Project ID' = projectCombo.Selected.'Project ID') &&
              ((checkboxBillable.Value && Billable=1)  || Billable = 0)
          )
    ),
    DateAsInt
)

I am unclear on your use of var1 and var2, but I'd consider getting rid of them and adjusting the formula based on the direct condition that you are setting them for.

 

Also, not sure what your Items properties are for your Project and Customer comboboxes (nor if you even need a combobox - unless you need multiple selections (which this formula does not adjust for) or searching) so, the Selected.xxxx  may need to be adjusted based on the items.

 

I hope this is helpful for you. 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

@RandyHayes  Thanks for your help.

But, I used your formula and changed it accordingly but the gallery is not showing up anything when I select the dates, Customer and even project.

CustomerCombo :
Items: 

Sort(Distinct('[dbo].[Vw_Customers]',vc_name),Result)

DisplayFields: 

["Result"]

 

ProjectCombo:
Items: 

 

Sort(Distinct('[dbo].[TsProject]',Descr),Result)

 

DisplayFields: 

 

["Result"]

 

 

Customer.png


and the Gallery is not showing any data, if there are no combobox selected, not even if the dates are selected by default.

Any Help??

RandyHayes
Super User III
Super User III

@MH3 

What is your formula on the Items?

I am more concerned, however, with the comboboxes.

In the Customer combobox - you ONLY have the vc_name column value - will this match to 'Customer ID'?

And for Project, you ONLY have the Descr column value - will this match to Project ID?

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

@RandyHayes I make you understand

I have a SQL Transaction Table which is named as TimeSheet
Table Fields:
1) Task  - Varchar
2) Date - Varchar
3) Customer - Int
4) Project  - Int
5) Billable - Int (stored as 0 or 1 )
6) UserId

Customer Table:
Table Fields:

1) vc_code - Integer (which is Customer Id in Customer Table and that ID is called as Foreign Key in TimeSheet table as Customer)
2) vc_name - Varchar (Which is Customer name)
3) Address - Varchar
4) Phone
and etc.

Project Table:
Table Fields:
1) Id - Int 
2) Descr - (Project Name) 

That's my SQL table Structure, actually I am matching Customer Text from CustomerCombo with Customer Number in TimeSheet which is in my Gallery Filter

RandyHayes
Super User III
Super User III

@MH3 

Understood.  My point is this - you are trying to filter based on the value of your comboboxes and your comboboxes do NOT contain any value that will relate to your Filter.

You are using the Distinct function in both of them.  Distinct returns ONLY one value...the value of the column you are doing distinct on.

So, if you need vc_code for your filter and you are doing distinct on vc_name, then you will not have the value you need in order to filter.

 

You will need to change the Items property on the CustomerCombo to:

 

Sort(
    AddColumns(
        GroupBy('[dbo].[Vw_Customers]',
            "vc_name",
            "_recs"
        ),
        "_customerID", First(_recs).vc_code
    ),
    vc_name
)

And set the DisplayFields to: ["vc_name"]

 

Your ProjectCombo Items needs to be:

Sort(
    AddColumns(
        GroupBy('[dbo].[TsProject]',
            "Descr",
            "_recs"
        ),
        "_projectID", First(_recs).Id
    ),
    Descr
)

And set the DisplayFields to ["Descr"]

 

Then, your filter formula is the following:

Sort
    With({_startDate: Value(Text(StartDate.SelectedDate,"[$-en-US]yyyymmdd")),
          _endDate: Value(Text(EndDate.SelectedDate,"[$-en-US]yyyymmdd"))},
      
          Filter(CollectTest1, 
              UserId=MyUserEmail &&
              (var1 && var2 && DateAsInt >= _startDate && DateAsInt <= _endDate) &&
              (IsBlank(CustomerCombo.Selected._customerID) || Customer = CustomerCombo.Selected._customerID) &&
              (IsBlank(ProjectCombo.Selected._projectID) || Project = ProjectCombo.Selected._projectID) &&
              ((checkboxBillable.Value && Billable=1)  || Billable = 0)
          )
    ),
    DateAsInt
)

 

I believe I have matched all the names properly based on what you provided, but correct as needed.

There is one that I do not see referenced anywhere - DateAsInt.   I did not see that in any of your schemas.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

@RandyHayes  Thanks your Formula worked.
But there is some problem. 
if I want to Filter the Gallery based on Customer Name Selection, the gallery is not showing any data.


CustomerFIlerint.png

What's wrong?

RandyHayes
Super User III
Super User III

@MH3 

I suspect in this scenario that this is because of the Dates.  There is nothing selected in your dates and with the current formula, it relies on there to be dates - there is no defaulting of dates.

 

I am still unclear on what var1 and var2 are in your formula and I left them in there to be consistent with your original formula.

 

If you want the ability to find items even when the dates are empty, then this should do it:

Sort
    With({_startDate: Value(Text(StartDate.SelectedDate,"[$-en-US]yyyymmdd")),
          _endDate: Value(Text(EndDate.SelectedDate,"[$-en-US]yyyymmdd"))},
      
          Filter(CollectTest1, 
              UserId=MyUserEmail &&
              (
               (IsBlank(StartDate.SelectedDate) || IsBlank(EndDate.SelectedDate)) ||
               (var1 && var2 && DateAsInt >= _startDate && DateAsInt <= _endDate)
              ) &&
              (IsBlank(CustomerCombo.Selected._customerID) || Customer = CustomerCombo.Selected._customerID) &&
              (IsBlank(ProjectCombo.Selected._projectID) || Project = ProjectCombo.Selected._projectID) &&
              ((checkboxBillable.Value && Billable=1)  || Billable = 0)
          )
    ),
    DateAsInt
)

 

Now, just like the cobobox values, this is going to depend on anything you might be doing in the Default of the datepickers.  I would make them Blank()

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Top Kudoed Authors
Users online (58,623)