web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id : rYLLQFfn/YmDr3ywFgdbpY
Power Apps - Building Power Apps
Unanswered

Show latest approved version of sharepoint document in Gallery

Like (0) ShareShare
ReportReport
Posted on 19 Jan 2024 10:22:10 by 25

Hi all!

In my Power App I have a gallery showing all files in a (SharePoint) document library. For this library, content approval is set to required and Minor version are created.

 

By default, the gallery will of course show all items.

 

How can I filter my gallery such that only the latest approved version will show to the user?

Filtering by "Approval Status" is not an option, as it will also hide the previous version(s).

 

 

Filter('SP Library', 'Content approval status' = "Approved")

 

 

For example: I want to show Version 2.0 (approved) to the user but 2.5 (draft) exists. If the user selects the document, version 2.0 is opened (not 2.5).

 

Thanks in advance for your help!

 

 

Categories:
I have the same question (0)
  • mmbr1606 Profile Picture
    14,353 Super User 2025 Season 2 on 19 Jan 2024 at 10:32:27
    Re: Show latest approved version of sharepoint document in Gallery

    hey @Gerard__ 

     

    try this instead:

     

    Collect(
    ApprovedItems,
    Filter(
    'SP Library',
    'Content approval status' = "Approved" &&
    'Version Number' = Max(
    Filter('SP Library', Title = ThisRecord.Title && 'Content approval status' = "Approved").'Version Number'
    )
    )
    );

    // Use 'ApprovedItems' as the items source for your gallery

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • Gerard__ Profile Picture
    25 on 19 Jan 2024 at 14:49:27
    Re: Show latest approved version of sharepoint document in Gallery

    @mmbr1606, thanks for your reply!

     

    I can't get it to work. For some reason the bold part is not working for me:

    Max(
    Filter('SP Library', Title = ThisRecord.Title && 'Content approval status' = "Approved").'Version number'

     

    For Title I'm using 'Title (Title0)' because the person setting up this library created a new title column for some reason.

    I'm running the collect function in the OnStart property of my app.

     

    Also, I'm not sure what this part is supposed to do so I do not have a clear idea what to change in order to make it work.

    In the mean time, I solved this issue by using the "Draft Item Security" option in SharePoint. Would still be interested though in how to fix this within PowerApps!

  • mmbr1606 Profile Picture
    14,353 Super User 2025 Season 2 on 20 Jan 2024 at 08:12:13
    Re: Show latest approved version of sharepoint document in Gallery

    hey @Gerard__ 

     

    please try this:

    Collect(
     ApprovedItems,
     Filter(
     'SP Library',
     'Content approval status' = "Approved" &&
     'Version Number' = Max(
     Filter(
     'SP Library', 
     'Title (Title0)' = ThisRecord.'Title (Title0)' &&
     'Content approval status' = "Approved"
     ).'Version Number'
     )
     )
    );

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • Gerard__ Profile Picture
    25 on 22 Jan 2024 at 08:19:42
    Re: Show latest approved version of sharepoint document in Gallery

    Hi @mmbr1606 

    I can't get it to work.

     

    Not sure how the (default) 'Version number' column is configured within SharePoint, but PowerApps Expects a number and apparantly isn't getting it. It seems that the following is not providing a number: 

    Filter(
     'SP Library', 
     'Title (Title0)' = ThisRecord.'Title (Title0)' &&
     'Content approval status' = "Approved"
     ).'Version number'

     

  • mmbr1606 Profile Picture
    14,353 Super User 2025 Season 2 on 22 Jan 2024 at 08:27:39
    Re: Show latest approved version of sharepoint document in Gallery

    hey @Gerard__ 

     

    try this please:

    Filter(
     'SP Library', 
     'Title (Title0)' = ThisRecord.'Title (Title0)' &&
     'Content approval status' = "Approved"
    ).Value('Version number')

     

    the Value() function converts text into number format.

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • Gerard__ Profile Picture
    25 on 22 Jan 2024 at 09:56:13
    Re: Show latest approved version of sharepoint document in Gallery

    That's not working either... 

     

    I tried the collect syntax without the 'Version number' = Max() part, and that is working.  

    As soon as I integrate that part it breaks down.

     

    Collect(
     ApprovedItems,
     Filter(
     'Document Management System',
     'Content approval status' = "Approved" && 'Version number' = Max(
     Filter(
     'Document Management System',
     'Title (Title0)' = ThisRecord.'Title (Title0)' && 'Content approval status' = "Approved"
     ).Value('Version number')
     )
     )
    );

     

  • mmbr1606 Profile Picture
    14,353 Super User 2025 Season 2 on 22 Jan 2024 at 12:02:59
    Re: Show latest approved version of sharepoint document in Gallery

    we can try a different approach:

    // First, create a collection to store the maximum version numbers for each title
    ClearCollect(
     MaxVersions,
     AddColumns(
     GroupBy(
     Filter(
     'Document Management System',
     'Content approval status' = "Approved"
     ),
     "Title (Title0)",
     "AllItems"
     ),
     "MaxVersion",
     Max(AllItems, 'Version number')
     )
    );
    
    // Now, use this collection in your main Collect function
    Collect(
     ApprovedItems,
     Filter(
     'Document Management System',
     'Content approval status' = "Approved" &&
     'Version number' = LookUp(MaxVersions, 'Title (Title0)' = ThisRecord.'Title (Title0)').MaxVersion
     )
    );

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • Gerard__ Profile Picture
    25 on 01 Feb 2024 at 11:33:10
    Re: Show latest approved version of sharepoint document in Gallery

    The ClearCollect part works and returns a table with all approved documents.

    The Collect part remains empty after running the OnStart.

     

  • mmbr1606 Profile Picture
    14,353 Super User 2025 Season 2 on 01 Feb 2024 at 11:45:02
    Re: Show latest approved version of sharepoint document in Gallery

    hey @Gerard__ 

     

    good to say one part works, for the other try this please:

     

    Collect(
     ApprovedItems,
     Filter(
     'Document Management System',
     'Content approval status' = "Approved" &&
     'Version number' = LookUp(MaxVersions, 'Title (Title0)' = Title (Title0), MaxVersion)
     )
    );

     

    Let me know if my answer helped solving your issue.

    If it did please accept as solution and give it a thumbs up so we can help others in the community.



    Greetings

  • Gerard__ Profile Picture
    25 on 01 Feb 2024 at 19:50:32
    Re: Show latest approved version of sharepoint document in Gallery

    The table remains empty still...

     

    Also, because of the MaxVersions table having only Approved documents, how will this function make all other documents show up which are now "draft" but do have an older "published" version?

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 714 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 419 Super User 2025 Season 2

#3
developerAJ Profile Picture

developerAJ 243

Last 30 days Overall leaderboard
Loading started
Loading complete