cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Winnietws
New Member

StartsWith function invalid with ||

20210930_140101.jpg

Hi, I am new to Powerapp and would like to seek help for this. I am trying to search two different columns, Name and Date ,within one search box and be able to filter my inputs by 'Date'. However, I got this error with I use the '||' function. 

4 REPLIES 4
RusselThomas
Microsoft
Microsoft

Hi @Winnietws ,

It looks like you're missing a close bracket after your second StartsWith() to close off the filter expression?

SortbyColumns(Filter(StartsWith()||StartsWith() ) ,"column", sortorder)

Hope this helps,

 

RT 

20210930_155133.jpg

 Hi RT , I included the closed bracket. I not sure about the error for 'Date'

Are you sure you want to use StartsWith on a date?

You could use StartsWith(Text(Date), TextSearchBox1_1.Text) to fix the error, but most likely you want to filter on an exact date using Date = DateValue(TextSearchBox1_1.Text)

RusselThomas
Microsoft
Microsoft

Hi @Winnietws ,

I would guess your problem stems from incompatible data types.

A Date type is not the same as a Text type.  This means, the string of today's date "2021/09/30" and the output of Today() are not equal because one is Text, and the other is a Date. "2021/09/30" = Today() = False.

Both sides of a comparison must be of the same types - always.

 

StartsWith() requires a text value to compare with another text value - if the data is stored as a Date type, then you can't use StartsWith() to compare that date to text unless you also convert the date to text first. 

Conversely, if the data you're comparing a Date type against is a Text type, you would need to convert it to a date type first for the comparison to work - and then you wouldn't use StartsWith() to do the comparison because it only does text comparisons.

 

Assuming your column is a Date type, you can try this - but quick disclaimer - I haven't tested it and I'm not going to type the whole thing, just insert the first part of your formula where .... is;

.... StartsWith(' name', TextSearchBox1_1.Text) || Date = DateValue(TextSearchBox1_1.Text)

You might get a delegation warning using the DateValue function inside a filter, so you can first define it using a With() statement and pass the result in - so your whole function goes inside the With()

With({convertedDate: DateValue(TextSearchBox1_1.Text)},
.... StartsWith(' name', TextSearchBox1_1.Text) || Date = convertedDate)
)

Note: If users are typing in dates, they could be doing it as dd/mm/yyyy or mm/dd/yyyy or yyyy/mm/dd and so forth - so if you aren't already using a datepicker to select dates, you might want to consider it to avoid validating date formats.

Hope this helps,

RT

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (6,074)