Skip to main content

Notifications

Power Platform Community / Forums / Building Power Apps / Only show last modifie...
Building Power Apps
Suggested answer

Only show last modified for distinct items in gallery

Posted on by 2

Hi All - Seems my previous question didnt post,

 

I hope someone can help. I have created an app to post information about sales of specific items. This is not in a form but rather controlled via a patch. I have done this because I do not want existing entries to be overwritten but rather a new entry to be added to the dataverse table every time I click submit. The reason for doing so is for me to track the lifecycle of the sales process (as probability changes and comments etc). I have created a unique ID field to ensure I can lookup the record in the underlying table

 

The challenge I am facing is the gallery, I only want the gallery to show 1 selector for each unique ID and when you click a specific item it should populate the input items with the details from the last modified record. I also do not want the gallery to show a previously submitted item which have an archived checkbox selected as these items would not be required going forward (but I would like to retain the history). I would assume this requires a formula in the items section of the gallery but I am not 100% sure?

 

You can see an example of the app in the attached file (I will be adding additional input fields such as probability and comments) but for now you can see the issue in the gallery on the left hand side where there is 2 "ABC" entries which both relate to the same unique ID the dates represented therein are the modified dates for each of those records.

 

Really appreciate the help!!

Categories:
  • markperrah Profile Picture
    markperrah 20 on at
    Only show last modified for distinct items in gallery
    my pleasure. glad to help.
    I had a project that needed this same info and i had to search many areas to piece together a working solution.
    Patching the data has been a big challenge for me. but this all seems to work now.
    Setting variables or using collections helps to target the data better for me. 

    Thia was a major project. It tracks all my time clock punches and keeps a record

  • CU16091800-0 Profile Picture
    CU16091800-0 8 on at
    Only show last modified for distinct items in gallery
    Mark, you are an absolute legend! This worked perfectly, thanks for all your help!
  • markperrah Profile Picture
    markperrah 20 on at
    Only show last modified for distinct items in gallery
    I put a label on screen with this text:
    If(tb_Name.Text in mySample.Name, "Name Exists", "New")
     
    If there is Name match in the source it reads "Name exists" of no match found reads "New"
     
     
    This can be used to let the user know that name exists,
    or just write the if statement in the Patch and pop up a message after they try to add it...
     
  • markperrah Profile Picture
    markperrah 20 on at
    Only show last modified for distinct items in gallery
  • markperrah Profile Picture
    markperrah 20 on at
    Only show last modified for distinct items in gallery
    I made this patch the selected record (Last name match in filtered gallery)
     
    Patch(mySample,
        Last(Filter(mySample, galFiltered.Selected.Value in Name)),
            ({
            Name: tb_Name.Text,
            Date: tb_Date.Text,
            'Sales Price': Value(tb_SPrice.Text)
           
        }));
  • markperrah Profile Picture
    markperrah 20 on at
    Only show last modified for distinct items in gallery
    You can make a modal popup with the data fields to be added and confirm that it doesn't already exist before the patch.
    I have an app that I have a new button and an edit button. 
    On edit I also set a variable called varRecord It captures the gallery selected item.
    The new/edit buttons each set a variable myEdit: edit=true, new=false
    then in the Patch I check the variable, if new I patch Defaults(source)
    if edit I patch varRecord.
     
    For your ID issue...
    You can do a search or find to compare ThisItem.ID against datasource.ID
    Are you planning to have a single gallery of just filtered "distinct" records? and then a few detail fields based on selection?
    A possible solution is to pull the entire datasource into a collection, then you can filter, distinct, patch and all via the collection.
  • markperrah Profile Picture
    markperrah 20 on at
    Only show last modified for distinct items in gallery
    for testing to be sure I had the correct dates and amounts I added a toggle to switch between first and last record of the name match:
    on a toggle control
    OnCheck:
    UpdateContext({firstLast: true})
    onUnCheck:
    UpdateContext({firstLast: false})
    ***
    in the filtered gallery:
    ThisItem.Value
    If(firstLast, 
    Last(Filter(mySample, ThisItem.Value in Name)).Date, 
    First(Filter(mySample, ThisItem.Value in Name)).Date)
    If(firstLast, 
    Last(Filter(mySample, ThisItem.Value in Name)).'Sales Price', 
    First(Filter(mySample, ThisItem.Value in Name)).'Sales Price')
    ***
    In the detail section:
    Gallery1.Selected.Value
    If(firstLast,
    Last(Filter(mySample, Gallery1.Selected.Value in Name)).Date,
    First(Filter(mySample, Gallery1.Selected.Value in Name)).Date)
    If(firstLast,
    Last(Filter(mySample, Gallery1.Selected.Value in Name)).'Sales Price',
    First(Filter(mySample, Gallery1.Selected.Value in Name)).'Sales Price')
     
  • markperrah Profile Picture
    markperrah 20 on at
    Only show last modified for distinct items in gallery
    Is the sales price part of the original data source?
    The Distinct basically filters the source to one column, so the rest of the fields of the source are stripped away.
    you need to reference the original source: match the selected or current item with the corresponding row form the source
     
    then you can do a filter just like we did for the date, but based on the gallery selection:
    Last(Filter(mySample, Gallery1.Selected.Value in Name)).'Sales Price'

     
     
  • CU16091800-0 Profile Picture
    CU16091800-0 8 on at
    Only show last modified for distinct items in gallery
    Hi Mark
     
    This worked perfectly for the gallery!! :)
     
    The only final issue I am running into is the text input boxes that rely on the gallery via a formula:
     
    Text(Gallery1.Selected.ColumnName) - For example Text(Gallery1.Selected.SalesPrice)
     
    Now that we are filtering down gallery to a single distinct column, it is no longer picking up the Sales Price column. If you can provide some guidance on how I can resolve that?
     
    Really appreciate all the help :)
  • CU16091730-0 Profile Picture
    CU16091730-0 2 on at
    Only show last modified for distinct items in gallery
    Hi Mark
     
    Thanks for the response
     
    The 1 issue I seem to be facing here is that I need to display item names but lookup distinct unique IDs (the reason for this is that a person may accidentally label an item with the same name as a previous submission) the Unique ID at least provides some protection against.
     
    I would also preferably like this in a gallery but if it will not work I will have to work around it, I just need to resolve the point above
     
    Thanks

Helpful resources

Quick Links

Welcome to the Power Platform…

We are thrilled to unveil the newly-launched Power Platform Communities!…

Community Update Sept 16…

Power Platform Community Update…

Welcome to the new Power Platform Community!…

We are excited to announce our new Copilot Cookbook Gallery in the Community…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 140,719

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,355

Leaderboard