cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
iwonder
Impactful Individual
Impactful Individual

With() is Slower?

Thank you for taking the time to read my question.

 

I had this code for my Gallery so that I can search my Dataverse table and be able to sort it by column based on what column a user clicks on.

 

I thought I'd try to clean it up and used a With()... but now I get a not responding, do I want to wait for PowerApps to finish message from my browser. Why is using the With() slower than my much longer code?

 

Original Code:

If(
    IsBlank(varBarStartDate),
    If(
        And(
            tCol = Blank(),
            tSort = Blank()
        ),
        Search(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                )
            ),
            AssetSearch.Text,
            "cra98_assettype",
            "cra98_assetstatus",
            "cra98_assignedto",
            "cra98_category",
            "cra98_citag",
            "cra98_manufacturername",
            "cra98_notes",
            "cra98_osname",
            "cra98_productname",
            "cra98_purchasedfrom",
            "cra98_serialnumber",
            "cra98_assetsite",
            "cra98_assetstatus",
            "cra98_warrantyinfo",
            "cra98_m3assetid"
        ),
        And(
            tCol = "ProductName",
            tSort = "Asc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            ProductName,
            Ascending
        ),
        And(
            tCol = "ProductName",
            tSort = "Desc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            ProductName,
            Descending
        ),
        And(
            tCol = "CITag",
            tSort = "Asc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            CITag,
            Ascending
        ),
        And(
            tCol = "CITag",
            tSort = "Desc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            CITag,
            Descending
        ),
        And(
            tCol = "M3AssetNum",
            tSort = "Asc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            M3AssetID,
            Ascending
        ),
        And(
            tCol = "M3AssetNum",
            tSort = "Desc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            M3AssetID,
            Descending
        ),
        And(
            tCol = "Site",
            tSort = "Asc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            AssetSite,
            Ascending
        ),
        And(
            tCol = "Site",
            tSort = "Desc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            AssetSite,
            Descending
        ),
        And(
            tCol = "AssignedTo",
            tSort = "Asc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            AssignedTo,
            Ascending
        ),
        And(
            tCol = "AssignedTo",
            tSort = "Desc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            AssignedTo,
            Descending
        ),
        And(
            tCol = "AssignedStatus",
            tSort = "Asc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            AssetStatus,
            Ascending
        ),
        And(
            tCol = "AssignedStatus",
            tSort = "Desc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            AssetStatus,
            Descending
        ),
        And(
            tCol = "Category",
            tSort = "Asc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            Category,
            Ascending
        ),
        And(
            tCol = "Category",
            tSort = "Desc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            Category,
            Descending
        ),
        And(
            tCol = "WarrExp",
            tSort = "Asc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            WarrantyExpireDate,
            Ascending
        ),
        And(
            tCol = "WarrExp",
            tSort = "Desc"
        ),
        Sort(
            Search(
                Filter(
                    Assets,
                    Region = varUserRegion
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
                "cra98_assetstatus",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            ),
            WarrantyExpireDate,
            Descending
        )
    ),//After here then filter from the column chart
    If(
        And(
            tCol = Blank(),
            tSort = Blank()
        ),
        Filter(
            Assets,
            Region in Split(
                varUserRegion,
                ","
            ),
            AssetType = varBarType,
            WarrantyExpireDate >= varBarStartDate,
            WarrantyExpireDate <= varBarEndDate
        ),
        And(
            tCol = "ProductName",
            tSort = "Asc"
        ),
        Filter(
            Assets,
            Region in Split(
                varUserRegion,
                ","
            ),
            AssetType = varBarType,
            WarrantyExpireDate >= varBarStartDate,
            WarrantyExpireDate <= varBarEndDate
        ),
        And(
            tCol = "ProductName",
            tSort = "Desc"
        ),
        Filter(
            Assets,
            Region in Split(
                varUserRegion,
                ","
            ),
            AssetType = varBarType,
            WarrantyExpireDate >= varBarStartDate,
            WarrantyExpireDate <= varBarEndDate
        ),
        And(
            tCol = "CITag",
            tSort = "Asc"
        ),
        Sort(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            CITag,
            Ascending
        ),
        And(
            tCol = "CITag",
            tSort = "Desc"
        ),
        Sort(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            CITag,
            Descending
        ),
        And(
            tCol = "M3AssetNum",
            tSort = "Asc"
        ),
        Sort(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            M3AssetID,
            Ascending
        ),
        And(
            tCol = "M3AssetNum",
            tSort = "Desc"
        ),
        Sort(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            M3AssetID,
            Descending
        ),
        And(
            tCol = "Site",
            tSort = "Asc"
        ),
        Sort(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            AssetSite,
            Ascending
        ),
        And(
            tCol = "Site",
            tSort = "Desc"
        ),
        Sort(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            AssetSite,
            Descending
        ),
        And(
            tCol = "AssignedTo",
            tSort = "Asc"
        ),
        Sort(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            AssignedTo,
            Ascending
        ),
        And(
            tCol = "AssignedTo",
            tSort = "Desc"
        ),
        Sort(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            AssignedTo,
            Descending
        ),
        And(
            tCol = "AssignedStatus",
            tSort = "Asc"
        ),
        Sort(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            AssetStatus,
            Ascending
        ),
        And(
            tCol = "AssignedStatus",
            tSort = "Desc"
        ),
        Sort(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            AssetStatus,
            Descending
        ),
        And(
            tCol = "Category",
            tSort = "Asc"
        ),
        Sort(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            Category,
            Ascending
        ),
        And(
            tCol = "Category",
            tSort = "Desc"
        ),
        Sort(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            Category,
            Descending
        ),
        And(
            tCol = "WarrExp",
            tSort = "Asc"
        ),
        Sort(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            WarrantyExpireDate,
            Ascending
        ),
        And(
            tCol = "WarrExp",
            tSort = "Desc"
        ),
        Sort(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            WarrantyExpireDate,
            Descending
        )
    )
)

 

New code using With()

With(
    {
        SearchData: Search(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                )
            ),
            AssetSearch.Text,
            "cra98_assettype",
            "cra98_assetstatus",
            "cra98_assignedto",
            "cra98_category",
            "cra98_citag",
            "cra98_manufacturername",
            "cra98_notes",
            "cra98_osname",
            "cra98_productname",
            "cra98_purchasedfrom",
            "cra98_serialnumber",
            "cra98_assetsite",
            "cra98_assetstatus",
            "cra98_warrantyinfo",
            "cra98_m3assetid"
        )
    },
    If(
        IsBlank(varBarStartDate),
        If(
            And(
                tCol = Blank(),
                tSort = Blank()
            ),
            SearchData,
            And(
                tCol = "ProductName",
                tSort = "Asc"
            ),
            Sort(
                SearchData,
                ProductName,
                Ascending
            ),
            And(
                tCol = "ProductName",
                tSort = "Desc"
            ),
            Sort(
                SearchData,
                ProductName,
                Descending
            ),
            And(
                tCol = "CITag",
                tSort = "Asc"
            ),
            Sort(
                SearchData,
                CITag,
                Ascending
            ),
            And(
                tCol = "CITag",
                tSort = "Desc"
            ),
            Sort(
                SearchData,
                CITag,
                Descending
            ),
            And(
                tCol = "M3AssetNum",
                tSort = "Asc"
            ),
            Sort(
                SearchData,
                M3AssetID,
                Ascending
            ),
            And(
                tCol = "M3AssetNum",
                tSort = "Desc"
            ),
            Sort(
                SearchData,
                M3AssetID,
                Descending
            ),
            And(
                tCol = "Site",
                tSort = "Asc"
            ),
            Sort(
                SearchData,
                AssetSite,
                Ascending
            ),
            And(
                tCol = "Site",
                tSort = "Desc"
            ),
            Sort(
                SearchData,
                AssetSite,
                Descending
            ),
            And(
                tCol = "AssignedTo",
                tSort = "Asc"
            ),
            Sort(
                SearchData,
                AssignedTo,
                Ascending
            ),
            And(
                tCol = "AssignedTo",
                tSort = "Desc"
            ),
            Sort(
                SearchData,
                AssignedTo,
                Descending
            ),
            And(
                tCol = "AssignedStatus",
                tSort = "Asc"
            ),
            Sort(
                SearchData,
                AssetStatus,
                Ascending
            ),
            And(
                tCol = "AssignedStatus",
                tSort = "Desc"
            ),
            Sort(
                SearchData,
                AssetStatus,
                Descending
            ),
            And(
                tCol = "Category",
                tSort = "Asc"
            ),
            Sort(
                SearchData,
                Category,
                Ascending
            ),
            And(
                tCol = "Category",
                tSort = "Desc"
            ),
            Sort(
                SearchData,
                Category,
                Descending
            ),
            And(
                tCol = "WarrExp",
                tSort = "Asc"
            ),
            Sort(
                SearchData,
                WarrantyExpireDate,
                Ascending
            ),
            And(
                tCol = "WarrExp",
                tSort = "Desc"
            ),
            Sort(
                SearchData,
                WarrantyExpireDate,
                Descending
            )
        ),//After here then filter from the column chart
        If(
            And(
                tCol = Blank(),
                tSort = Blank()
            ),
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            And(
                tCol = "ProductName",
                tSort = "Asc"
            ),
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            And(
                tCol = "ProductName",
                tSort = "Desc"
            ),
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ),
                AssetType = varBarType,
                WarrantyExpireDate >= varBarStartDate,
                WarrantyExpireDate <= varBarEndDate
            ),
            And(
                tCol = "CITag",
                tSort = "Asc"
            ),
            Sort(
                Filter(
                    Assets,
                    Region in Split(
                        varUserRegion,
                        ","
                    ),
                    AssetType = varBarType,
                    WarrantyExpireDate >= varBarStartDate,
                    WarrantyExpireDate <= varBarEndDate
                ),
                CITag,
                Ascending
            ),
            And(
                tCol = "CITag",
                tSort = "Desc"
            ),
            Sort(
                Filter(
                    Assets,
                    Region in Split(
                        varUserRegion,
                        ","
                    ),
                    AssetType = varBarType,
                    WarrantyExpireDate >= varBarStartDate,
                    WarrantyExpireDate <= varBarEndDate
                ),
                CITag,
                Descending
            ),
            And(
                tCol = "M3AssetNum",
                tSort = "Asc"
            ),
            Sort(
                Filter(
                    Assets,
                    Region in Split(
                        varUserRegion,
                        ","
                    ),
                    AssetType = varBarType,
                    WarrantyExpireDate >= varBarStartDate,
                    WarrantyExpireDate <= varBarEndDate
                ),
                M3AssetID,
                Ascending
            ),
            And(
                tCol = "M3AssetNum",
                tSort = "Desc"
            ),
            Sort(
                Filter(
                    Assets,
                    Region in Split(
                        varUserRegion,
                        ","
                    ),
                    AssetType = varBarType,
                    WarrantyExpireDate >= varBarStartDate,
                    WarrantyExpireDate <= varBarEndDate
                ),
                M3AssetID,
                Descending
            ),
            And(
                tCol = "Site",
                tSort = "Asc"
            ),
            Sort(
                Filter(
                    Assets,
                    Region in Split(
                        varUserRegion,
                        ","
                    ),
                    AssetType = varBarType,
                    WarrantyExpireDate >= varBarStartDate,
                    WarrantyExpireDate <= varBarEndDate
                ),
                AssetSite,
                Ascending
            ),
            And(
                tCol = "Site",
                tSort = "Desc"
            ),
            Sort(
                Filter(
                    Assets,
                    Region in Split(
                        varUserRegion,
                        ","
                    ),
                    AssetType = varBarType,
                    WarrantyExpireDate >= varBarStartDate,
                    WarrantyExpireDate <= varBarEndDate
                ),
                AssetSite,
                Descending
            ),
            And(
                tCol = "AssignedTo",
                tSort = "Asc"
            ),
            Sort(
                Filter(
                    Assets,
                    Region in Split(
                        varUserRegion,
                        ","
                    ),
                    AssetType = varBarType,
                    WarrantyExpireDate >= varBarStartDate,
                    WarrantyExpireDate <= varBarEndDate
                ),
                AssignedTo,
                Ascending
            ),
            And(
                tCol = "AssignedTo",
                tSort = "Desc"
            ),
            Sort(
                Filter(
                    Assets,
                    Region in Split(
                        varUserRegion,
                        ","
                    ),
                    AssetType = varBarType,
                    WarrantyExpireDate >= varBarStartDate,
                    WarrantyExpireDate <= varBarEndDate
                ),
                AssignedTo,
                Descending
            ),
            And(
                tCol = "AssignedStatus",
                tSort = "Asc"
            ),
            Sort(
                Filter(
                    Assets,
                    Region in Split(
                        varUserRegion,
                        ","
                    ),
                    AssetType = varBarType,
                    WarrantyExpireDate >= varBarStartDate,
                    WarrantyExpireDate <= varBarEndDate
                ),
                AssetStatus,
                Ascending
            ),
            And(
                tCol = "AssignedStatus",
                tSort = "Desc"
            ),
            Sort(
                Filter(
                    Assets,
                    Region in Split(
                        varUserRegion,
                        ","
                    ),
                    AssetType = varBarType,
                    WarrantyExpireDate >= varBarStartDate,
                    WarrantyExpireDate <= varBarEndDate
                ),
                AssetStatus,
                Descending
            ),
            And(
                tCol = "Category",
                tSort = "Asc"
            ),
            Sort(
                Filter(
                    Assets,
                    Region in Split(
                        varUserRegion,
                        ","
                    ),
                    AssetType = varBarType,
                    WarrantyExpireDate >= varBarStartDate,
                    WarrantyExpireDate <= varBarEndDate
                ),
                Category,
                Ascending
            ),
            And(
                tCol = "Category",
                tSort = "Desc"
            ),
            Sort(
                Filter(
                    Assets,
                    Region in Split(
                        varUserRegion,
                        ","
                    ),
                    AssetType = varBarType,
                    WarrantyExpireDate >= varBarStartDate,
                    WarrantyExpireDate <= varBarEndDate
                ),
                Category,
                Descending
            ),
            And(
                tCol = "WarrExp",
                tSort = "Asc"
            ),
            Sort(
                Filter(
                    Assets,
                    Region in Split(
                        varUserRegion,
                        ","
                    ),
                    AssetType = varBarType,
                    WarrantyExpireDate >= varBarStartDate,
                    WarrantyExpireDate <= varBarEndDate
                ),
                WarrantyExpireDate,
                Ascending
            ),
            And(
                tCol = "WarrExp",
                tSort = "Desc"
            ),
            Sort(
                Filter(
                    Assets,
                    Region in Split(
                        varUserRegion,
                        ","
                    ),
                    AssetType = varBarType,
                    WarrantyExpireDate >= varBarStartDate,
                    WarrantyExpireDate <= varBarEndDate
                ),
                WarrantyExpireDate,
                Descending
            )
        )
    )
)

 

I am fixing it up so its easier to read but also, so that I can add one more search, on a date field... not sure if that's possible

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions

@iwonder 
Oh My!!

What is slowest is the amount of time you are spending typing all that in!  You are repeating things over and over and over and PowerApps will need to evaluate over and over and over.

You are missing one critical function - SortByColumns!

With that function, you can use your variables to specify the sort column and direction both.  So there is NO need to make so many If conditions and then Sort statements.

 

Your entire formula can be replaced with the following:

With(
    {
        SearchData: Search(
            Filter(Assets,
                Region in Split(varUserRegion, ",") &&
                (IsBlank(varBarStartDate) || WarrantyExpireDate >= varBarStartDate) &&
                (IsBlank(varBarEndDate) || WarrantyExpireDate <= varBarEndDate) &&
                (IsBlank(varBarType) || AssetType = varBarType),

            ),
            AssetSearch.Text, "cra98_assettype", "cra98_assetstatus", "cra98_assignedto", "cra98_category", "cra98_citag", "cra98_manufacturername",
                              "cra98_notes", "cra98_osname", "cra98_productname", "cra98_purchasedfrom", "cra98_serialnumber", "cra98_assetsite",
                              "cra98_assetstatus", "cra98_warrantyinfo", "cra98_m3assetid"
        );
    _order: Switch(tSort, "Asc", "Ascending", "Desending");
    _col: Switch(tCol, "ProductName", "ProductName", 
                       "CITag", "CITag", 
                       "M3AssetNum", "M3AssetID", 
                       "Site", "AssetSite", 
                       "AssignedTo", "AssignedTo", 
                       "AssignedStatus", "AssetStatus", 
                       "Category", "Category", 
                       "WarrExp", "WarrantyExpireDate",
                       <defaultColumnNameHere>
                )
    },
    
   SortByColumns(SearchData,
      _col,
      Coalesce(tSort, <defaultOrder>)
   )
)

Ideally, you can eliminate even more by simply setting the tSort variable to be either "Ascending" or "Descending" in your other formulas.  And also, tCol, to just be the real name of the column you want to sort on.

 

You should have only ONE filter function in your formula.  It should specify the criteria in a Boolean way to produce either true or false results per record.  This will eliminate the multiple filters and If's for the conditions you have.

 

Note: for the scenario where the variables are blank, specify the default column names and default sort order in the locations in the formula above.

 

Also, as mentioned, you will need the real column names for the Sort to work properly - not the Display Names.

 

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

6 REPLIES 6

@iwonder 
Oh My!!

What is slowest is the amount of time you are spending typing all that in!  You are repeating things over and over and over and PowerApps will need to evaluate over and over and over.

You are missing one critical function - SortByColumns!

With that function, you can use your variables to specify the sort column and direction both.  So there is NO need to make so many If conditions and then Sort statements.

 

Your entire formula can be replaced with the following:

With(
    {
        SearchData: Search(
            Filter(Assets,
                Region in Split(varUserRegion, ",") &&
                (IsBlank(varBarStartDate) || WarrantyExpireDate >= varBarStartDate) &&
                (IsBlank(varBarEndDate) || WarrantyExpireDate <= varBarEndDate) &&
                (IsBlank(varBarType) || AssetType = varBarType),

            ),
            AssetSearch.Text, "cra98_assettype", "cra98_assetstatus", "cra98_assignedto", "cra98_category", "cra98_citag", "cra98_manufacturername",
                              "cra98_notes", "cra98_osname", "cra98_productname", "cra98_purchasedfrom", "cra98_serialnumber", "cra98_assetsite",
                              "cra98_assetstatus", "cra98_warrantyinfo", "cra98_m3assetid"
        );
    _order: Switch(tSort, "Asc", "Ascending", "Desending");
    _col: Switch(tCol, "ProductName", "ProductName", 
                       "CITag", "CITag", 
                       "M3AssetNum", "M3AssetID", 
                       "Site", "AssetSite", 
                       "AssignedTo", "AssignedTo", 
                       "AssignedStatus", "AssetStatus", 
                       "Category", "Category", 
                       "WarrExp", "WarrantyExpireDate",
                       <defaultColumnNameHere>
                )
    },
    
   SortByColumns(SearchData,
      _col,
      Coalesce(tSort, <defaultOrder>)
   )
)

Ideally, you can eliminate even more by simply setting the tSort variable to be either "Ascending" or "Descending" in your other formulas.  And also, tCol, to just be the real name of the column you want to sort on.

 

You should have only ONE filter function in your formula.  It should specify the criteria in a Boolean way to produce either true or false results per record.  This will eliminate the multiple filters and If's for the conditions you have.

 

Note: for the scenario where the variables are blank, specify the default column names and default sort order in the locations in the formula above.

 

Also, as mentioned, you will need the real column names for the Sort to work properly - not the Display Names.

 

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!

Hi @RandyHayes 

 

I have no idea why I did not think SortByColumns()... Thank you

 

2 questions:

 

1. I don't understand what is happening in this part

(IsBlank(varBarStartDate) || WarrantyExpireDate >= varBarStartDate) && (IsBlank(varBarEndDate) || WarrantyExpireDate <= varBarEndDate) && (IsBlank(varBarType) || AssetType = varBarType)

 

I would like to filter my gallery by Region because I need to limit who can see what. That is why I have the Split(). After that, I want to use Search() to find records in the filtered dataset so that users don't need an exact match. They type these values into a TextInput called AssetSearch. Right now I am only able to search on Text values. If I type in a date value... something like 01/27/2022 the search does not work. Maybe that part goes in the Filter instead of Search and I use Match() to find out if a date has been entered? Or maybe I need to add 2 date pickers, otherwise I need to parse out 2 dates from a string somehow...

 

The other way to limit what is shown in the gallery is for the user to look at a Column Chart. They click on a column which brings up a gallery of all the different item types for that column. They can then select one which sets 3 variables:

Set(varBarStartDate,Date(Left(ThisItem._rYearMonth,4),Mid(ThisItem._rYearMonth,5,2),1));
Set(varBarEndDate,Date(Left(ThisItem._rYearMonth,4),Value(Mid(ThisItem._rYearMonth,5,2))+1,0));
Set(varBarType,ThisItem._rAssetType);

The user is then taken to the main Assets screen and I want to filter my Gallery on these values (auto populate the search criteria). The values are put into the AssetSearch Input box so the user can see what the filter value is but I want to act on them independently as there is more than one value / column being searched. That's why my original code checked if IsBlank(varBarStartDate). If it's blank, then the users is not coming from the Column Chart, but rather is using AssetSearch to find records.

 

 

2. I am able to sort Ascending on any column, but Descending does not work. Here is the code as I have implemented it and I'm not sure why Descending is not working:

With(
    {
        SearchData: Search(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ) && (IsBlank(varBarStartDate) || WarrantyExpireDate >= varBarStartDate) && (IsBlank(varBarEndDate) || WarrantyExpireDate <= varBarEndDate) && (IsBlank(varBarType) || AssetType = varBarType)
            ),
            AssetSearch.Text,
            "cra98_assettype",
            "cra98_assetstatus",
            "cra98_assignedto",
            "cra98_category",
            "cra98_citag",
            "cra98_manufacturername",
            "cra98_notes",
            "cra98_osname",
            "cra98_productname",
            "cra98_purchasedfrom",
            "cra98_serialnumber",
            "cra98_assetsite",
            "cra98_assetstatus",
            "cra98_warrantyinfo",
            "cra98_m3assetid"
        ),
        _order: Switch(
            tSort,
            "Asc",
            "Ascending",
            "Descending"
        ),
        _col: Switch(
            tCol,
            "ProductName",
            "cra98_productname",
            "CITag",
            "cra98_citag",
            "M3AssetNum",
            "cra98_m3assetid",
            "Site",
            "cra98_assetsite",
            "AssignedTo",
            "cra98_assignedto",
            "AssignedStatus",
            "cra98_assetstatus",
            "Category",
            "cra98_category",
            "WarrExp",
            "WarrantyExpireDate",
            "cra98_productname"
        )
    },
    SortByColumns(
        SearchData,
        _col,
        Coalesce(
            tSort,
            Ascending
        )
    )
)

 

Thanks again for all your help. I learn so much from you and am truly greatful.

Hi @RandyHayes 

 

This part finally clicked this morning... I blame Friday afternoon...

 

 

(IsBlank(varBarStartDate) || WarrantyExpireDate >= varBarStartDate) && (IsBlank(varBarEndDate) || WarrantyExpireDate <= varBarEndDate) && (IsBlank(varBarType) || AssetType = varBarType)

 

 

and I am now able to sort Descending as well.

 

I also fixed up my code so that it uses the proper field names and Ascending and Descending.

 

With(
    {
        SearchData: Search(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ) && (IsBlank(varBarStartDate) || WarrantyExpireDate >= varBarStartDate) && (IsBlank(varBarEndDate) || WarrantyExpireDate <= varBarEndDate) && (IsBlank(varBarType) || AssetType = varBarType) //This checks to see if the variables are blank or not. If they're not then they're a part of the filter
            ),
            AssetSearch.Text,
            "cra98_assettype",
            "cra98_assetstatus",
            "cra98_assignedto",
            "cra98_category",
            "cra98_citag",
            "cra98_manufacturername",
            "cra98_notes",
            "cra98_osname",
            "cra98_productname",
            "cra98_purchasedfrom",
            "cra98_serialnumber",
            "cra98_assetsite",
            "cra98_warrantyinfo",
            "cra98_m3assetid"
        )
    },
    SortByColumns(
        SearchData,
        tCol,
        Coalesce(
            tSort,
            Ascending
        )
    )
)

 

thanks

@RandyHayes 

 

In the end I had to change it to this so that I could filter using the Input Box AssetSearch OR search using variables populated when a user clicks on a Gallery item on a different screen

 

With(
    {
        SearchData: 
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                ) && (IsBlank(varBarStartDate) || WarrantyExpireDate >= varBarStartDate) && (IsBlank(varBarEndDate) || WarrantyExpireDate <= varBarEndDate) && (IsBlank(varBarType) || AssetType = varBarType) //This checks to see if the variables are blank or not. If they're not then they're a part of the filter
            )
    },
    SortByColumns(
        If(IsBlank(varBarStartDate),Search(SearchData,AssetSearch.Text,
            "cra98_assettype",
            "cra98_assetstatus",
            "cra98_assignedto",
            "cra98_category",
            "cra98_citag",
            "cra98_manufacturername",
            "cra98_notes",
            "cra98_osname",
            "cra98_productname",
            "cra98_purchasedfrom",
            "cra98_serialnumber",
            "cra98_assetsite",
            "cra98_warrantyinfo",
            "cra98_m3assetid"
        ),SearchData),
        tCol,
        Coalesce(
            tSort,
            Ascending
        )
    )
)

Hi @RandyHayes 

 

I'm continuing to test and it seems my original formula without With() works better than the formula you suggested. It seems I hit a delegation issue with your formula and I don't with my original formula.

 

With my original formula I can search my Dataverse table and return the expected records (8 records). With the formula you suggested using the same search term I only get 1... because it's in the first 500 records. My formula is not slow either....

 

I do like your formula as it's more compact, so how can I make it work as well as my LONG formula?

 

Thanks again for all your help and time.

Hi @RandyHayes 

 

This is much shorter thanks to you... again.

 

This still responds as I expect with 8 records in my test search and is shorter than the original and doesn't seem to have a delegation issue.

 

If(
    IsBlank(varBarStartDate),
    If(
        And(
            tCol = Blank(),
            tSort = Blank()
        ),
        Search(
            Filter(
                Assets,
                Region in Split(
                    varUserRegion,
                    ","
                )
            ),
            AssetSearch.Text,
            "cra98_assettype",
            "cra98_assetstatus",
            "cra98_assignedto",
            "cra98_category",
            "cra98_citag",
            "cra98_manufacturername",
            "cra98_notes",
            "cra98_osname",
            "cra98_productname",
            "cra98_purchasedfrom",
            "cra98_serialnumber",
            "cra98_assetsite",
			"cra98_m3assetid",
            "cra98_warrantyinfo",
            "cra98_m3assetid"
        ),
        
        With({tData:
            Search(
                Filter(
                    Assets,
                    Region in Split(
                    varUserRegion,
                    ","
                )
                ),
                AssetSearch.Text,
                "cra98_assettype",
                "cra98_assetstatus",
                "cra98_assignedto",
                "cra98_category",
                "cra98_citag",
                "cra98_manufacturername",
                "cra98_notes",
                "cra98_osname",
                "cra98_productname",
                "cra98_purchasedfrom",
                "cra98_serialnumber",
                "cra98_assetsite",
    			"cra98_m3assetid",
                "cra98_warrantyinfo",
                "cra98_m3assetid"
            )},SortByColumns(tData,tCol,tSort
    ))),//After here then filter from the column chart
    If(
        And(
            tCol = Blank(),
            tSort = Blank()
        ),
        Filter(
            Assets,
            Region in Split(
                varUserRegion,
                ","
            ),
            AssetType = varBarType,
            WarrantyExpireDate >= varBarStartDate,
            WarrantyExpireDate <= varBarEndDate
        ),
        With({tData:Filter(
            Assets,
            Region in Split(
                varUserRegion,
                ","
            ),
            AssetType = varBarType,
            WarrantyExpireDate >= varBarStartDate,
            WarrantyExpireDate <= varBarEndDate
        )},SortByColumns(tData,tCol,tSort)
    ))
)

 

Thoughts?

 

Thanks again

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!   This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions in the Forums to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersNumber of SolutionsSuper UsersNumber of Solutions @anandm08  23 @WarrenBelz  31 @DBO_DV  10 @Amik  19 AmínAA 6 @mmbr1606  12 @rzuber  4 @happyume  7 @Giraldoj  3@ANB 6 (tie)   @SpongYe  6 (tie)     Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Community MembersSolutionsSuper UsersSolutions @anandm08  10@WarrenBelz 25 @DBO_DV  6@mmbr1606 14 @AmínAA 4 @Amik  12 @royg  3 @ANB  10 @AllanDeCastro  2 @SunilPashikanti  5 @Michaelfp  2 @FLMike  5 @eduardo_izzo  2   Meekou 2   @rzuber  2   @Velegandla  2     @PowerPlatform-P  2   @Micaiah  2     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 3:Community MembersSolutionsSuper UsersSolutionsPower Apps anandm0861WarrenBelz86DBO_DV25Amik66Michaelfp13mmbr160647Giraldoj13FLMike31AmínAA13SpongYe27     Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Week 4:Community MembersSolutionsSuper UsersSolutionsPower Apps DBO-DV21WarranBelz26Giraldoj7mmbr160618Muzammmil_0695067Amik14samfawzi_acml6FLMike12tzuber6ANB8   SunilPashikanti8

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (639)