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 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 (2,956)