Skip to main content

Notifications

Power Apps - Power Apps Pro Dev & ISV
Unanswered

Problem with 2-conditions in Switch-Function while Filter-Function

Posted on 25 Nov 2024 00:01:37 by 12

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 SP 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 addressed.

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

  • ronaldwalcott Profile Picture
    ronaldwalcott 855 on 26 Nov 2024 at 22:44:20
    Problem with 2-conditions in Switch-Function while Filter-Function
    You have several variables in this statement such as
    varFolderPathSelectionFiles
    Where are these variables set and what are they set to?
  • Adam_9595 Profile Picture
    Adam_9595 12 on 26 Nov 2024 at 22:28:16
    Problem with 2-conditions in Switch-Function while Filter-Function
    Hello everyone,
     
    i did it! PowerApps did not recognized Modified By and Created by, so i have to rename the terms into
     
    '{Editor}'.DisplayName
    '{Author}'.DisplayName
     
    Again, thank you for your help
  • Adam_9595 Profile Picture
    Adam_9595 12 on 26 Nov 2024 at 19:09:13
    Problem with 2-conditions in Switch-Function while Filter-Function
    Hi @ronaldwalcott,

    in the item-property of gallery. Red underlined Sections are the error.

    Thank you
  • ronaldwalcott Profile Picture
    ronaldwalcott 855 on 26 Nov 2024 at 05:31:47
    Problem with 2-conditions in Switch-Function while Filter-Function
    This is not clear. Where are you getting the error?
  • Adam_9595 Profile Picture
    Adam_9595 12 on 25 Nov 2024 at 23:02:23
    Problem with 2-conditions in Switch-Function while Filter-Function
    Hi @mmbr1606,

    thank you for your message and help. Unfortunately, the code don't work. 

    I have postet in my frist post (look attachment "message") my reply to your post, because, if i submit my post,
    i get everytime an error-message, that the request is blocked. . I`dont know, why? I`ll write to service support.
     
    Thank you 
    Adam
  • mmbr1606 Profile Picture
    mmbr1606 9,936 on 25 Nov 2024 at 07:05:26
    Problem with 2-conditions in Switch-Function while Filter-Function
    If(
        !IsBlank(TextInput1_1.Text),
        Search(
            Filter(
                varSelectedLibrary,
                '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(
                varSelectedLibrary,
                '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(
                varSelectedLibrary,
                '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(
            varSelectedLibrary,
            '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)
            )
        )
    )
    
    hey
     
    can u try this:
     
    put it in the onchange of directory

     
     
     
     
    UpdateContext({varSelectedLibrary: If(SelectionDirectory.Selected.Value = "Dokumente2", Dokumente2, DL_Permission)})
    
     
     
    if it helped please mark as verified answer
     
     
    cheers
     
     
     

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,246

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,884

Leaderboard