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

Specified cast is not valid

Dear all,

 

I don't understand why one of my formulas is not working. I get the error "Specified cast is not valid". (see attached screenshot)

 

 

Items: Filter('Employment term (mshr)', Employment.'Employment (mshr)' = DropEmployments.Selected.'Employment (mshr)',ValidTo <= Today())

 

 

I use a Dropdown (source virtual entity "Employment (mshr)") and depending on this dropdown the gallery should show all associated "Employment terms" that have the ValidTo date greater or equal Today. Without the "ValidTo <= Today()" part the formula works as expected.

Maybe somebody has a hint...

 

Best

Alex

 

10 REPLIES 10
Drrickryp
Super User
Super User

@Speed1 

The error seems to indicate that 'Employment term (mshr)' is not a valid datasource or the field chosen in the equation doesn't exist in the datasource.  The second part of the filter (the equation part) should be a field in the datasource.  

 

Filter(
         'Employment term (mshr)', 'Employment (mshr)' = 
            DropEmployments.Selected.'Employment(mshr)', ValidTo <= Today()
)

 

I'm not sure that the "Employment." is necessary if 'Employment (mshr)' is an actual field in 'Employment term (mshr)'. 

 

Speed1
Frequent Visitor

Hi @Drrickryp,

 

thanks for your answer, you are right, I have changed the formula as below. This way its clearer.

 

 

Filter(
    'Employment term (mshr)',
    'Primary Field' = DropEmployments.Selected.'Primary Field',ValidTo >= Today()
)

 

 But still I get the same error... When I remove the  "ValidTo >= Today()" filter it works, but I need this filter to show only the new employments

 

Drrickryp
Super User
Super User

@Speed1 

Then it depends on the format for the Validto column in your datasource.  Is it date/time or text? 

Speed1
Frequent Visitor

It's date and time. I have no idea why it's not working...

 

 

Drrickryp
Super User
Super User

@Speed1 

Try 

 

Filter(
        'Employment term (mshr)',
        'Primary Field' = DropEmployments.Selected.'Primary Field' &&
          DateDiff(Today(),ValidTo,Days
          )>= 0
)


 

Speed1
Frequent Visitor

@Drrickryp 

Now I get only the "Filter Warning for big data sets". Unfortunately the Gallery in the PowerApp is always empty, checked on 5-6 different cases. 😞

Drrickryp
Super User
Super User

@Speed1 

Good grief!,  Instead of Today() see if Now() works. 

Speed1
Frequent Visitor

Already tried, I'm sorry... 😞

Drrickryp
Super User
Super User

@Speed1 

It looks like you are using Dataverse.  If so, create a new column, give it a name and make it a calculated type.

In the formula for the calculation, put DIFFINDAYS(NOW(),ValidTo) and save it.  Open Views, ActiveView and add the new column and see if there is data in it.

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (4,989)