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

Converting non-delegated IF-statement to delegated

Hi!

I'm using a SharePoint-list for my application which has worked well.

As a result of bad planning and unexpected usage the data volume has of course increased above the threshold of what PowerApps can fetch and a few of my functions have stopped working.

 

Most of the functions have been converted to use simpler and delegated statements instead - though I'm having an issue with an IF-statement.

 

The following non-delegated code is used on a button;

 

 

If(
    !IsEmpty(
        Filter(
            SalesData;
            label_title.Text in Title && datepicker_datum.SelectedDate in Datum
        )
    );
    Notify(
        "Fel! Datum är redan inrapporterat.";
        NotificationType.Error
    );
    Patch(
        SalesData;
        Defaults(SalesData);
        {Title: label_title.Text};
        {Datum: datepicker_datum.SelectedDate};
        {Försäljning: textinput_försäljning.Text};
        {Netto: textinput_netto.Text};
        {'Antal artiklar': textinput_antalartiklar.Text};
        {'Antal köp': textinput_antalköp.Text};
        {Kommentarer: textinput_kommentarer.Text};
        {'Antal besökare': textinput_antalbesökare.Text}
    )
)

 

The snippet filters the SalesData SharePoint-list and either patches or notifys with an error - depending if the selected date in datepicker datepicker_datum already exists.

 

Now the database is a long list and the structure something like this;

 

StoreDateSales in $Net price# of articles# of salesVisitorsComments

 

Now each store (nowadays around 10~) reports the data every day, e.g.

 

BigStore2021-04-088000,003000,001000500800

 

BigStore2021-04-072500,001500,0050030080

 

CoffeeShop2021-04-088000,003000,001000500800

 

CoffeeShop2021-04-073000,00

800,00

200250150

 

 

I would really love some input on how to accomplish this in a delegated scenario.

I was thinking of filtering on e.g. BigStore using a variable and fetch it to a collection - though I'm getting stuck there as well, getting the delegation to work. 

 

How would you best go about this issue? 

1 ACCEPTED SOLUTION

Accepted Solutions
WarrenBelz
Super User III
Super User III

@knastim ,

The in Filter is not Delegable - neither is the Date Filter. You can get around in possibly as they seem to simply need to equal, but not the Date Filter. I have a blog on Delegation that may be useful to you - in particular look at the work-around for dates.

However a suggestion that might work - if the newest 2,000 records that match the Title label will do the job for you, set your limit to this and try

With(
   {
      wSales:
      Filter(
         Sort(
            SalesData;
            ID;
            Descending
         );
         Title=label_title.Text
      )
   };
   If(
      !IsBlank(
         LookUp(
            wSales;
            Text(datepicker_datum.SelectedDate;ShortDate) = Text(Datum;ShortDate)
         )
      );
      Notify(
         "Fel! Datum är redan inrapporterat.";
         NotificationType.Error
      );
      Patch(
         SalesData;
         Defaults(SalesData);
         {
            Title: label_title.Text;
            Datum: datepicker_datum.SelectedDate;
            Försäljning: textinput_försäljning.Text;
            Netto: textinput_netto.Text;
            'Antal artiklar': textinput_antalartiklar.Text;
            'Antal köp': textinput_antalköp.Text;
            Kommentarer: textinput_kommentarer.Text;
            'Antal besökare': textinput_antalbesökare.Text
         }
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

8 REPLIES 8
WarrenBelz
Super User III
Super User III

@knastim ,

The in Filter is not Delegable - neither is the Date Filter. You can get around in possibly as they seem to simply need to equal, but not the Date Filter. I have a blog on Delegation that may be useful to you - in particular look at the work-around for dates.

However a suggestion that might work - if the newest 2,000 records that match the Title label will do the job for you, set your limit to this and try

With(
   {
      wSales:
      Filter(
         Sort(
            SalesData;
            ID;
            Descending
         );
         Title=label_title.Text
      )
   };
   If(
      !IsBlank(
         LookUp(
            wSales;
            Text(datepicker_datum.SelectedDate;ShortDate) = Text(Datum;ShortDate)
         )
      );
      Notify(
         "Fel! Datum är redan inrapporterat.";
         NotificationType.Error
      );
      Patch(
         SalesData;
         Defaults(SalesData);
         {
            Title: label_title.Text;
            Datum: datepicker_datum.SelectedDate;
            Försäljning: textinput_försäljning.Text;
            Netto: textinput_netto.Text;
            'Antal artiklar': textinput_antalartiklar.Text;
            'Antal köp': textinput_antalköp.Text;
            Kommentarer: textinput_kommentarer.Text;
            'Antal besökare': textinput_antalbesökare.Text
         }
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

View solution in original post

Hi Warren,

 

Thank you very much for your valued help - and lots of great information on your blog, I'll make sure to catch up on that!

I understand what we're trying to accomplish with the snippet above though I'm unable to apply it as I'm getting 

Expected type 'Boolean'. Found type 'Record' on the Patch-bit.
 
I suspect it has to do with the "Datum"-field as it's the only one that is not a simple text-field, in turn due to dates getting different formats due to locale, browser settings etc. and it was the "easy fix".
Using the Patch expression by itself it works though not in the combination above... do you have any suggestions?

Hi @knastim ,

What item is this on - this does not change the structure as I simply copied your Patch - we just need to find the error and fix it.

 

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

WarrenBelz
Super User III
Super User III

Hi @knastim ,

Just checking if you got the result you were looking for on this thread. Happy to help further if not.

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

knastim
Frequent Visitor

Hi again Warren,

 

Apologies for the delay and thank you for your response.

I'm not certain which item it refers to and I've been trying to find it out without luck.

Regardless if Patch uses the entire line of columns to update - or if I pick a random one it still throws the error. 

 

knastim_1-1618386459392.png

 

knastim_0-1618386444761.png

 

Though if I replace Patch with whatever, the code works.

Below snippet works just perfect in other words, it notifys me whenever an item exists (though of course doesn't do anything if it doesn't).

 

With(
   {
      wSales:
      Filter(
         Sort(
            SalesData;
            ID;
            Descending
         );
         Title=label_title.Text
      )
   };
   If(
      !IsBlank(
         LookUp(
            wSales;
            Text(datepicker_datum.SelectedDate;ShortDate) = Text(Datum;ShortDate)
         )
      );
      Notify(
         "Fel! Datum är redan inrapporterat.";
         NotificationType.Error
      );
       true
   )
)

 

knastim
Frequent Visitor

Hiya gang!

I still haven't managed to figure out the odd behaviour on the Patch (as it should behave the same)... does anyone have any idea of what I could try? 

 

Thank you!

@knastim ,

Go through the Patch and try only one field. If there is no error, then add another one until you find the one that is causing the error.

Hi again Warren!

Thank you for your reply.

Tried and tested... without luck. I have absolutely no idea why it doesn't comply. 

 

Though I, uh... solved it. Instead of Patch on the button I simply triggered a hidden timer - which in turn has the Patch on it's OnTimerEnd. 😂 Peculiar issues require peculiar solutions!

 

I know your snippet is supposed to work just as intended - so I'll go ahead and mark it as such.

Thank you very much for your input and help!

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

R2 (Green) 768 x 460px.png

Microsoft Dynamics 365 & Power Platform User Professionals

DynamicsCon is a FREE, 4 half-day virtual learning experience for 11,000+ Microsoft Business Application users and professionals.

Users online (1,977)