cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
TBuente
Resolver I
Resolver I

Patch whichever table is selected without nested IF

Hi,

 

I am building an app that allows users to track inventory. This app consists of many tables for many different office locations for my company. Since each office location is on its own table, I would like users to be able to select which location a device belongs to, and then patch the device created/managed in the correct table.

 

Currently, I have a working version of this; however, it is slow and I feel like there may be a better solution.

Currently I'm using nested IFs, like this:

If(SelectedItem.Location = "New Orleans", 
Patch(
    NewOrleansTable,
    First(Filter(NewOrleansTable, SerialNumber = SelectedItem.SerialNumber)),
    {
        AssignedUser: 
        If(SpareCheckedEdit = true, "Spare Device",
        If(AssignVis = false,
            EditAssignedUser.Text,
            UserInput_1.Selected.DisplayName)),

        Manufacturer: If(ManuVis = false,
        EditManu.Text,
        ManuEdit.Selected.Value),

        Model: EditModel.Text,

        AssetTag:EditAssetTag.Text,
        Hostname: EditHostName.Text,

        Location: If(LocVis = false,
        EditLoc.Text,
        LocationEdi.Selected.Value),
        
        DeviceType: If(DeviceTypeVis=false,
        EditDevType.Text,
        DeviceEdit.Selected.Value),

        SerialNumber: EditSerial.Text,
        WarrantyExpiration: EditExpireDate.SelectedDate,

        OS: If(OSVis = false,
        EditOS.Text,
        OSEdit.Selected.Value),

        OfficeVersion: If(OffVerVis = false,
        EditOffice.Text,
        OfficeVerEdit.Selected.Value),

        Extras: EditExtras.Text
    }
),
If(SelectedItem.Location = "Gaithersburg", 
Patch(
    GaithersburgTable,
    First(Filter(GaithersburgTable, SerialNumber = SelectedItem.SerialNumber)),
    {
        AssignedUser: 
        If(SpareCheckedEdit = true, "Spare Device",
        If(AssignVis = false,
            EditAssignedUser.Text,
            UserInput_1.Selected.DisplayName)),

        Manufacturer: If(ManuVis = false,
        EditManu.Text,
        ManuEdit.Selected.Value),

        Model: EditModel.Text,

        AssetTag:EditAssetTag.Text,
        Hostname: EditHostName.Text,

        Location: If(LocVis = false,
        EditLoc.Text,
        LocationEdi.Selected.Value),
        
        DeviceType: If(DeviceTypeVis=false,
        EditDevType.Text,
        DeviceEdit.Selected.Value),

        SerialNumber: EditSerial.Text,
        WarrantyExpiration: EditExpireDate.SelectedDate,

        OS: If(OSVis = false,
        EditOS.Text,
        OSEdit.Selected.Value),

        OfficeVersion: If(OffVerVis = false,
        EditOffice.Text,
        OfficeVerEdit.Selected.Value),

        Extras: EditExtras.Text
    }
),
If(SelectedItem.Location = "Spare Extras", 
Patch(
    Table20,
    First(Filter(Table20, SerialNumber = SelectedItem.SerialNumber)),
    {
        AssignedUser: 
        If(SpareCheckedEdit = true, "Spare Device",
        If(AssignVis = false,
            EditAssignedUser.Text,
            UserInput_1.Selected.DisplayName)),

        Manufacturer: If(ManuVis = false,
        EditManu.Text,
        ManuEdit.Selected.Value),

        Model: EditModel.Text,

        AssetTag:EditAssetTag.Text,
        Hostname: EditHostName.Text,

        Location: If(LocVis = false,
        EditLoc.Text,
        LocationEdi.Selected.Value),
        
        DeviceType: If(DeviceTypeVis=false,
        EditDevType.Text,
        DeviceEdit.Selected.Value),

        SerialNumber: EditSerial.Text,
        WarrantyExpiration: EditExpireDate.SelectedDate,

        OS: If(OSVis = false,
        EditOS.Text,
        OSEdit.Selected.Value),

        OfficeVersion: If(OffVerVis = false,
        EditOffice.Text,
        OfficeVerEdit.Selected.Value),

        Extras: EditExtras.Text
    }
),

 

While this does work fine, the patching takes quite some time, and I would like to reduce the time that this takes. Is there a better way to say something like this:

 

If location = New Orleans, Gaithersburg, etc then Patch( *corresponding location here* )?

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @TBuente ,

Based on the issue that you mentioned, I think this issue may be related to Nested If function specified in your app.

 

I have made a test on my side, please consider modify your formula as below:

Patch(
      Switch(
             SelectedItem.Location,
             "New Orleans", NewOrleansTable
             "Gaithersburg", GaithersburgTable,
             "Spare Extras", Table20
      ),
      First(Filter(
                   Switch(
                           SelectedItem.Location,
                           "New Orleans", NewOrleansTable
                           "Gaithersburg", GaithersburgTable,
                           "Spare Extras", Table20
                   ),
                   SerialNumber = SelectedItem.SerialNumber
      )),
      {
        AssignedUser: 
        If(SpareCheckedEdit = true, "Spare Device",
        If(AssignVis = false, EditAssignedUser.Text,UserInput_1.Selected.DisplayName)),
        Manufacturer: If(ManuVis = false,
        EditManu.Text,
        ManuEdit.Selected.Value),
        Model: EditModel.Text,
        AssetTag:EditAssetTag.Text,
        Hostname: EditHostName.Text,
        Location: If(LocVis = false,EditLoc.Text,LocationEdi.Selected.Value),
        DeviceType: If(DeviceTypeVis=false,EditDevType.Text,DeviceEdit.Selected.Value),
        SerialNumber: EditSerial.Text,
        WarrantyExpiration: EditExpireDate.SelectedDate,
        OS: If(OSVis = false,EditOS.Text,OSEdit.Selected.Value),
        OfficeVersion: If(OffVerVis = false,EditOffice.Text,OfficeVerEdit.Selected.Value),
        Extras: EditExtras.Text
    }
)

 

Please consider take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-xida-msft
Community Support
Community Support

Hi @TBuente ,

Based on the issue that you mentioned, I think this issue may be related to Nested If function specified in your app.

 

I have made a test on my side, please consider modify your formula as below:

Patch(
      Switch(
             SelectedItem.Location,
             "New Orleans", NewOrleansTable
             "Gaithersburg", GaithersburgTable,
             "Spare Extras", Table20
      ),
      First(Filter(
                   Switch(
                           SelectedItem.Location,
                           "New Orleans", NewOrleansTable
                           "Gaithersburg", GaithersburgTable,
                           "Spare Extras", Table20
                   ),
                   SerialNumber = SelectedItem.SerialNumber
      )),
      {
        AssignedUser: 
        If(SpareCheckedEdit = true, "Spare Device",
        If(AssignVis = false, EditAssignedUser.Text,UserInput_1.Selected.DisplayName)),
        Manufacturer: If(ManuVis = false,
        EditManu.Text,
        ManuEdit.Selected.Value),
        Model: EditModel.Text,
        AssetTag:EditAssetTag.Text,
        Hostname: EditHostName.Text,
        Location: If(LocVis = false,EditLoc.Text,LocationEdi.Selected.Value),
        DeviceType: If(DeviceTypeVis=false,EditDevType.Text,DeviceEdit.Selected.Value),
        SerialNumber: EditSerial.Text,
        WarrantyExpiration: EditExpireDate.SelectedDate,
        OS: If(OSVis = false,EditOS.Text,OSEdit.Selected.Value),
        OfficeVersion: If(OffVerVis = false,EditOffice.Text,OfficeVerEdit.Selected.Value),
        Extras: EditExtras.Text
    }
)

 

Please consider take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

That appears to be what I needed! I briefly skimmed over documentation about Switch, but quickly forgot about that function.

 

Thank you!

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,123)