cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

SortByColumns not working when using a variable

Have an issue can't seem to solve. Have a data table MonthTable with 12 months of sales figure and want to display as trailing 12 months eg: if we are in April then sort starting with April (last year) thru March (this year). Table has 2 columns MonthNumber and Sales.

 

I have a lookup table to get the sort order based on current month. Works when hard coded, but does not using variable.

 

On Visible screen set the variable, to test I hard coded it for April ie: month 4

UpdateContext({SortString:"[4,5,6,7,8,9,10,11,12,1,2,3]"});
 
then on table Items use
SortByColumns(MonthTable, "MonthNumber", SortString)
does not work but
SortByColumns(MonthTable, "MonthNumber", [4,5,6,7,8,9,10,11,12,1,2,3])
does work!!🤔
 
Any ideas?
Thanks
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
Super User III
Super User III

@rmc
You can’t sort a string. Don’t put your table between quotes in the OnVisible property then everything will work just fine.

UpdateContext({SortString:[4,5,6,7,8,9,10,11,12,1,2,3]});

—-
Please Accept as Solution if this post answered your question so others may find it more quickly. If you found this post helpful consider giving it a Thumbs Up.

View solution in original post

4 REPLIES 4
Super User III
Super User III

@rmc
You can’t sort a string. Don’t put your table between quotes in the OnVisible property then everything will work just fine.

UpdateContext({SortString:[4,5,6,7,8,9,10,11,12,1,2,3]});

—-
Please Accept as Solution if this post answered your question so others may find it more quickly. If you found this post helpful consider giving it a Thumbs Up.

View solution in original post

Super User III
Super User III

Please disregard - @mdevaney has answered before I posted

 

 

Frequent Visitor

 

Thankyou for the quick reply. That solved that issue perfectly!

 

However the goal is to have this sort automatically based on current month. So I put all the 12 sort strings (SortOrderMonths) in a table (SortText) and tried this

UpdateContext({SortString: LookUp(SortText,MonthNumber=Month(Now()),SortOrderMonths)});
 
which did not work.I also tried putting this directly in Items of the table
 
SortByColumns(MonthTable, "MonthNumber", LookUp(SortText,MonthNumber=Month(Now()),SortOrderMonths))
which also did not work.
 
Stumped!
 
 

 

 

@rmc 

Suggest you post your additional question in a new thread and close this one.  I am not necessarily sure I have the answer here so its best to start a new thread.

 

---
Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Helpful resources

Announcements
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

Top Solution Authors
Top Kudoed Authors
Users online (66,761)