cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
ebraga
Helper II
Helper II

Sorting a Gallery with Multiple If Statements

Hello All,

I used this discussion post to successfully use a button to sort my gallery. https://powerusers.microsoft.com/t5/Building-Power-Apps/Sort-Icon-connection-to-Gallery/m-p/396671#M...

 

However, I have 3 buttons that will be used in sorting my gallery, each one corresponding to a field in my gallery. I cannot seem to get the if statement correct for the Items property of the gallery with multiple if statements. this is my current items property: 

SortByColumns(Search('[dbo].[v_nye_inventory]',TextInput1.Text,"itemnmbr"),"lotnumbr", If(ascendingOrderlot=true,Ascending,Descending))

 

Can someone help with this?

 

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@ebraga 

I would consider a slightly different approach to this.

On the three buttons...let's just say for example that they are "Lot Number", "Big Number", "Little Number".

 

In the OnSelect of the Lot Number button, set the following formula:    UpdateContext({lclSortColumn: "lotnumber"})

In the OnSelect of the Big Number button, set the following formula:    UpdateContext({lclSortColumn: "bignumber"})

In the OnSelect of the Little Number button, set the following formula:    UpdateContext({lclSortColumn: "littlenumber"})

 

Now, on your formula:

SortByColumns(
    Search('[dbo].[v_nye_inventory]',
        TextInput1.Text, "itemnmbr"
    ),
    Coalesce(lclSortColumn, "lotnumber"), 
    If(ascendingOrderlot, Ascending, Descending)
)

 

In the above, we just use the value in the lclSortColumn to specify the column we want to sort by as set by the buttons.  If the variable lclSortColumn has NOT been set by a button, then we use the Coalesce function to give us a default, in this case lotnumber.

 

No need for any other If's in your formula.

 

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!

View solution in original post

1 REPLY 1
RandyHayes
Super User III
Super User III

@ebraga 

I would consider a slightly different approach to this.

On the three buttons...let's just say for example that they are "Lot Number", "Big Number", "Little Number".

 

In the OnSelect of the Lot Number button, set the following formula:    UpdateContext({lclSortColumn: "lotnumber"})

In the OnSelect of the Big Number button, set the following formula:    UpdateContext({lclSortColumn: "bignumber"})

In the OnSelect of the Little Number button, set the following formula:    UpdateContext({lclSortColumn: "littlenumber"})

 

Now, on your formula:

SortByColumns(
    Search('[dbo].[v_nye_inventory]',
        TextInput1.Text, "itemnmbr"
    ),
    Coalesce(lclSortColumn, "lotnumber"), 
    If(ascendingOrderlot, Ascending, Descending)
)

 

In the above, we just use the value in the lclSortColumn to specify the column we want to sort by as set by the buttons.  If the variable lclSortColumn has NOT been set by a button, then we use the Coalesce function to give us a default, in this case lotnumber.

 

No need for any other If's in your formula.

 

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!

View solution in original post

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

PA Community Call

Power Apps Community Call

Next call is happening on April 21st at 8a PST.

MBAS Carousel

Sign up for our May 4th event!

May the fourth be with you, join us online!

secondImage

Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Top Solution Authors
Top Kudoed Authors
Users online (40,728)