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

Patch function & IsEmpty function

Hello all, I would like to patch the below data , every time i change it , it is creating a new row. So i wrote the below code . If there is no data with Concatenate_date_1.Text i would like to create defaults row, or else, I would like to patch to the existing data. Could you help me where i am going wrong .? Thanks

If(
IsEmpty(
Filter(
Todolist_QC,
Dateid_Todo = Concatenate_date_1.Text
)
),


Patch(Todolist_QC,
Defaults(Todolist_QC),
{
Date:DatePicker_todo.SelectedDate,
Shift:'Schicht value_to_do'.Selected.Value,
'Gaskontrolle & ggf. Zylinder wechseln ':TextInput7.Text,
'Lösungsmittel entsorgen':TextInput7_1.Text,
'Lieferung annehmen & auspacken':TextInput7_2.Text,
BOS:TextInput7_3.Text,
GMP:TextInput7_4.Text,
Dateid_Todo:Concatenate(Text(DatePicker_todo.SelectedDate,"[$-en-US]yyyy"), "_", Text(DatePicker_todo.SelectedDate,"[$-en-US]mm"), "_", Text(DatePicker_todo.SelectedDate,"[$-en-US]dd"))

}
)
)

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@Gunayathi 

If what you are stating is that if there is an existing record, you want to update it and if there is none, then you want to create one, then consider the following formula:

Patch(Todolist_QC,
    Coalesce(LookUp(Todolist_QC, Dateid_Todo = Concatenate_date_1.Text),  Defaults(Todolist_QC)),
    {
        Date:DatePicker_todo.SelectedDate,
        Shift:'Schicht value_to_do'.Selected.Value,
        'Gaskontrolle & ggf. Zylinder wechseln ':TextInput7.Text,
        'Lösungsmittel entsorgen':TextInput7_1.Text,
        'Lieferung annehmen & auspacken':TextInput7_2.Text,
        BOS:TextInput7_3.Text,
        GMP:TextInput7_4.Text,
        Dateid_Todo:Concatenate(Text(DatePicker_todo.SelectedDate,"[$-en-US]yyyy"), "_", Text(DatePicker_todo.SelectedDate,"[$-en-US]mm"), "_", Text(DatePicker_todo.SelectedDate,"[$-en-US]dd"))
    }
)

The Coalesce statement in this formula will lookup a record based on the criteria of the Dateid_Todo.  If it exists, then it is used as the basis of your Patch (i.e. you will be updating a record), if not, then the Defaults will be used (you will be creating a new record).

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

2 REPLIES 2
RandyHayes
Super User
Super User

@Gunayathi 

If what you are stating is that if there is an existing record, you want to update it and if there is none, then you want to create one, then consider the following formula:

Patch(Todolist_QC,
    Coalesce(LookUp(Todolist_QC, Dateid_Todo = Concatenate_date_1.Text),  Defaults(Todolist_QC)),
    {
        Date:DatePicker_todo.SelectedDate,
        Shift:'Schicht value_to_do'.Selected.Value,
        'Gaskontrolle & ggf. Zylinder wechseln ':TextInput7.Text,
        'Lösungsmittel entsorgen':TextInput7_1.Text,
        'Lieferung annehmen & auspacken':TextInput7_2.Text,
        BOS:TextInput7_3.Text,
        GMP:TextInput7_4.Text,
        Dateid_Todo:Concatenate(Text(DatePicker_todo.SelectedDate,"[$-en-US]yyyy"), "_", Text(DatePicker_todo.SelectedDate,"[$-en-US]mm"), "_", Text(DatePicker_todo.SelectedDate,"[$-en-US]dd"))
    }
)

The Coalesce statement in this formula will lookup a record based on the criteria of the Dateid_Todo.  If it exists, then it is used as the basis of your Patch (i.e. you will be updating a record), if not, then the Defaults will be used (you will be creating a new record).

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Gunayathi
Frequent Visitor

Perfect it works, 🙂

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.

Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on June 15, 2022 at 8am PDT.

PA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

This training provides practical hands-on experience in creating Power Apps solutions in a full-day of instructor-led App creation workshop.

PA.JPG

New Release Planning Portal (Preview)

Check out our new release planning portal, an interactive way to plan and prepare for upcoming features in Power Platform.

Top Solution Authors
Top Kudoed Authors
Users online (1,849)