Search code examples
powerappspowerapps-formula

Is this consider hardcoding in Powerapps canvas-app functions?


Below is what I have written, may I know if the canvas-app functions are considered hardcoded... :

If(
    "EC - Empire Complex" in BuildingDropdown.Selected.Value &&
        "Storey 1" in StoreyDropdown.Selected.Value &&
        "Office" in AreaNameDropdown.Selected.Value,
    Distinct(
        Filter(
            Area,
            "1" in buildingID,
            "Storey 1" in storey_x0020_,
            "Office" in areaName_x0020_),
        areaDescription_x0020_)))

Solution

  • Based on the first edit that you had (where you had the entire expression, not only the simplified version), this can definitely be improved. To answer the main question - yes, the expression is hard-coding the values in the in expressions where it doesn't need to.

    For example, look at the beginning of this expression:

    If(
        "EC - Empire Complex" in BuildingDropdown.Selected.Value &&
            "Storey 1" in StoreyDropdown.Selected.Value &&
            "Office" in AreaNameDropdown.Selected.Value,
        Distinct(
            Filter(
                Area,
                "1" in buildingID,
                "Storey 1" in storey_x0020_,
                "Office" in areaName_x0020_),
            areaDescription_x0020_),
        If(
            "EC - Empire Complex" in BuildingDropdown.Selected.Value &&
                "Storey 1" in StoreyDropdown.Selected.Value &&
                "Meeting rooms" in AreaNameDropdown.Selected.Value,
            Distinct(
                Filter(
                    Area,
                    "1" in buildingID,
                    "Storey 1" in storey_x0020_,
                    "Meeting rooms" in areaName_x0020_),
                areaDescription_x0020_),
            If(
                "EC - Empire Complex" in BuildingDropdown.Selected.Value &&
                    "Storey 1" in StoreyDropdown.Selected.Value &&
                    "Pantry" in AreaNameDropdown.Selected.Value,
                Distinct(
                    Filter(
                        Area,
                        "1" in buildingID,
                        "Storey 1" in storey_x0020_,
                        "Pantry" in areaName_x0020_),
                    areaDescription_x0020_),
                // And many more lines
    

    The expressions in the Filter statements seem to come directly from the conditions in the If clause, so they can be used directly in them:

    If(
        "EC - Empire Complex" in BuildingDropdown.Selected.Value,
        Distinct(
            Filter(
                Area,
                "1" in buildingID,
                StoreyDropdown.Selected.Value in storey_x0020_,
                AreaNameDropdown.Selected.Value in areaName_x0020_),
            areaDescription_x0020_))