Skip to main content

Notifications

Power Apps - Power Apps Pro Dev & ISV
Suggested answer

Probleme bei mehrfache Bedingungen in Switch-Funktion

Posted on by 16

Hello everyone,

I am working on my file explorer, which is supposed to access files and folders from two document libraries.
Users can access the SharePoint document libraries "DL_Permission" or "Dokumente2" via the DropDown control "SelectionDirectory" The Sharepoint entries are loaded into a gallery.

In the Item property of the gallery, I am using the following code:

If(
    !IsBlank(TextInput1_1.Text),
    Search(
        Filter(
            Switch(
                SelectionDirectory.Selected.Value, // Here
                "Dokumente2", Dokumente2, // Here
                "DL_Permission", DL_Permission // Here
            ),
            'Folder path' = varFolderPathSelectionFiles &&
            (
                IsBlank(FilterValue.Text) || 
                (varFilterItem_00_05 = "'File name with extension'" && Text(FilterValue.Text) in 'File name with extension') ||
                (varFilterItem_00_05 = "Modified" && Text(FilterValue.Text) in Text(Modified)) ||
                (varFilterItem_00_05 = "Modifiedby" && Text(FilterValue.Text) in 'Modified By'.DisplayName) ||
                (varFilterItem_00_05 = "Created" && Text(FilterValue.Text) in Text(Created)) ||
                (varFilterItem_00_05 = "Createdby" && Text(FilterValue.Text) in 'Created By'.DisplayName)
            )
        ),
        TextInput1_1.Text, 
        'File name with extension'
    ),
    varFilterSortDirection_00_05 = 1, 
    Sort(
        Filter(
            Switch(
                SelectionDirectory.Selected.Value, // Here
                "Dokumente2", Dokumente2, // Here
                "DL_Permission", DL_Permission // Here 
            ),
            'Folder path' = varFolderPathSelectionFiles &&
            (
                IsBlank(FilterValue.Text) || 
                (varFilterItem_00_05 = "'File name with extension'" && Text(FilterValue.Text) in 'File name with extension') ||
                (varFilterItem_00_05 = "Modified" && Text(FilterValue.Text) in Text(Modified)) ||
                (varFilterItem_00_05 = "Modifiedby" && Text(FilterValue.Text) in 'Modified By'.DisplayName) ||
                (varFilterItem_00_05 = "Created" && Text(FilterValue.Text) in Text(Created)) ||
                (varFilterItem_00_05 = "Createdby" && Text(FilterValue.Text) in 'Created By'.DisplayName)
            )
        ),
        Switch(
            varFilterItem_00_05,
            "'File name with extension'", 'File name with extension',
            "Modified", Modified,
            "Modifiedby", 'Modified By'.DisplayName,
            "Created", Created,
            "Createdby", 'Created By'.DisplayName
        ),
        SortOrder.Ascending
    ),
    varFilterSortDirection_00_05 = 2,
    Sort(
        Filter(
            Switch(
                SelectionDirectory.Selected.Value, // Here
                "Dokumente2", Dokumente2, // Here
                "DL_Permission", DL_Permission // Here
            ),
            'Folder path' = varFolderPathSelectionFiles &&
            (
                IsBlank(FilterValue.Text) || 
                (varFilterItem_00_05 = "'File name with extension'" && Text(FilterValue.Text) in 'File name with extension') ||
                (varFilterItem_00_05 = "Modified" && Text(FilterValue.Text) in Text(Modified)) ||
                (varFilterItem_00_05 = "Modifiedby" && Text(FilterValue.Text) in 'Modified By'.DisplayName) ||
                (varFilterItem_00_05 = "Created" && Text(FilterValue.Text) in Text(Created)) ||
                (varFilterItem_00_05 = "Createdby" && Text(FilterValue.Text) in 'Created By'.DisplayName)
            )
        ),
        Switch(
            varFilterItem_00_05,
            "'File name with extension'", 'File name with extension',
            "Modified", Modified,
            "Modifiedby", 'Modified By'.DisplayName,
            "Created", Created,
            "Createdby", 'Created By'.DisplayName
        ),
        SortOrder.Descending
    ),
    Filter(
        Switch(
            SelectionDirectory.Selected.Value, // Here
            "Dokumente2", Dokumente2, // Here
            "DL_Permission", DL_Permission // Here
        ),
        'Folder path' = varFolderPathSelectionFiles &&
        (
            IsBlank(FilterValue.Text) || 
            (varFilterItem_00_05 = "'File name with extension'" && Text(FilterValue.Text) in 'File name with extension') ||
            (varFilterItem_00_05 = "Modified" && Text(FilterValue.Text) in Text(Modified)) ||
            (varFilterItem_00_05 = "Modifiedby" && Text(FilterValue.Text) in 'Modified By'.DisplayName) ||
            (varFilterItem_00_05 = "Created" && Text(FilterValue.Text) in Text(Created)) ||
            (varFilterItem_00_05 = "Createdby" && Text(FilterValue.Text) in 'Created By'.DisplayName)
        )
    )
)
Unfortunately, PowerApps reports an error with the Switch function in the context of the Filter function (Highlighted lines with "// Here") when 2 conditions "Dokumente2", Dokumente2, and "DL_Permission", DL_Permission are used.
With just one condition, the code works perfectly fine. After extensive research and despite asking in ChatGPT, I couldn't find the error.

What changes should I make in the code so that PowerApps accepts both conditions?

I would be grateful for any help!

Adam


 
  • Suggested answer
    SaiRT14 Profile Picture
    SaiRT14 1,334 on at
    Probleme bei mehrfache Bedingungen in Switch-Funktion
     
    The issue arises because the Switch function in Power Apps expects each condition (key-value pair) to be separated by a single comma.
     
    Replace the Switch logic with an If function.  
     
     If(
        !IsBlank(TextInput1_1.Text),
        Search(
            Filter(
                If(
                    SelectionDirectory.Selected.Value = "Dokumente2", Dokumente2,
                    SelectionDirectory.Selected.Value = "DL_Permission", DL_Permission,
                    Blank() // Default case
                ),
                'Folder path' = varFolderPathSelectionFiles &&
                (
                    IsBlank(FilterValue.Text) || 
                    (varFilterItem_00_05 = "'File name with extension'" && Text(FilterValue.Text) in 'File name with extension') ||
                    (varFilterItem_00_05 = "Modified" && Text(FilterValue.Text) in Text(Modified)) ||
                    (varFilterItem_00_05 = "Modifiedby" && Text(FilterValue.Text) in 'Modified By'.DisplayName) ||
                    (varFilterItem_00_05 = "Created" && Text(FilterValue.Text) in Text(Created)) ||
                    (varFilterItem_00_05 = "Createdby" && Text(FilterValue.Text) in 'Created By'.DisplayName)
                )
            ),
            TextInput1_1.Text, 
            'File name with extension'
        ),
        varFilterSortDirection_00_05 = 1, 
        Sort(
            Filter(
                If(
                    SelectionDirectory.Selected.Value = "Dokumente2", Dokumente2,
                    SelectionDirectory.Selected.Value = "DL_Permission", DL_Permission,
                    Blank() // Default case
                ),
                'Folder path' = varFolderPathSelectionFiles &&
                (
                    IsBlank(FilterValue.Text) || 
                    (varFilterItem_00_05 = "'File name with extension'" && Text(FilterValue.Text) in 'File name with extension') ||
                    (varFilterItem_00_05 = "Modified" && Text(FilterValue.Text) in Text(Modified)) ||
                    (varFilterItem_00_05 = "Modifiedby" && Text(FilterValue.Text) in 'Modified By'.DisplayName) ||
                    (varFilterItem_00_05 = "Created" && Text(FilterValue.Text) in Text(Created)) ||
                    (varFilterItem_00_05 = "Createdby" && Text(FilterValue.Text) in 'Created By'.DisplayName)
                )
            ),
            Switch(
                varFilterItem_00_05,
                "'File name with extension'", 'File name with extension',
                "Modified", Modified,
                "Modifiedby", 'Modified By'.DisplayName,
                "Created", Created,
                "Createdby", 'Created By'.DisplayName
            ),
            SortOrder.Ascending
        ),
        varFilterSortDirection_00_05 = 2,
        Sort(
            Filter(
                If(
                    SelectionDirectory.Selected.Value = "Dokumente2", Dokumente2,
                    SelectionDirectory.Selected.Value = "DL_Permission", DL_Permission,
                    Blank() // Default case
                ),
                'Folder path' = varFolderPathSelectionFiles &&
                (
                    IsBlank(FilterValue.Text) || 
                    (varFilterItem_00_05 = "'File name with extension'" && Text(FilterValue.Text) in 'File name with extension') ||
                    (varFilterItem_00_05 = "Modified" && Text(FilterValue.Text) in Text(Modified)) ||
                    (varFilterItem_00_05 = "Modifiedby" && Text(FilterValue.Text) in 'Modified By'.DisplayName) ||
                    (varFilterItem_00_05 = "Created" && Text(FilterValue.Text) in Text(Created)) ||
                    (varFilterItem_00_05 = "Createdby" && Text(FilterValue.Text) in 'Created By'.DisplayName)
                )
            ),
            Switch(
                varFilterItem_00_05,
                "'File name with extension'", 'File name with extension',
                "Modified", Modified,
                "Modifiedby", 'Modified By'.DisplayName,
                "Created", Created,
                "Createdby", 'Created By'.DisplayName
            ),
            SortOrder.Descending
        ),
        Filter(
            If(
                SelectionDirectory.Selected.Value = "Dokumente2", Dokumente2,
                SelectionDirectory.Selected.Value = "DL_Permission", DL_Permission,
                Blank() // Default case
            ),
            'Folder path' = varFolderPathSelectionFiles &&
            (
                IsBlank(FilterValue.Text) || 
                (varFilterItem_00_05 = "'File name with extension'" && Text(FilterValue.Text) in 'File name with extension') ||
                (varFilterItem_00_05 = "Modified" && Text(FilterValue.Text) in Text(Modified)) ||
                (varFilterItem_00_05 = "Modifiedby" && Text(FilterValue.Text) in 'Modified By'.DisplayName) ||
                (varFilterItem_00_05 = "Created" && Text(FilterValue.Text) in Text(Created)) ||
                (varFilterItem_00_05 = "Createdby" && Text(FilterValue.Text) in 'Created By'.DisplayName)
            )
        )
    )
     
    try the above and let me know if it fixes your issue.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,591

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,090

Leaderboard