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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Trying to store two di...
Power Apps
Answered

Trying to store two different data structure in one gallery ( Likes and Comments)

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hello Powerapps Community , 

 

I am trying to store comments and count "likes" on those comments, but apparently I am also trying to store data about the number of total likes from  the users for that comment on the  same Gallery . There is an underlying data structure issue in the gallery and I require support for it 🙂 .

 

So far the problem looks like this here below the people like this filter is actually using the numbers from total number of comments rather than total number of likes . 

 

Arsal_1-1630922927548.png

 

 

The Sharepoint list looks like this so its clear what field is what . 

 

Arsal_0-1630922669134.png

 

This is the code for gallery that is in Items property . 

 

With(
 {
 records:
 Filter(
 'IT Helpdesk Comments',
 CommentsID = Gallery_ActiveTickets_1.Selected.ID
 )
 },
 ForAll(
 Sequence(CountRows(records)), 
 Patch(
 Last(
 FirstN(
 records, 
 Value
 )
 ), 
 {rowNumber: Value}
 )
 )

 

This is the Onselect property of the post comment where, when a user comments in Richtext editor , it is then being patched to the gallery . 

 

Patch('IT Helpdesk Comments',{CommentsID:Gallery_ActiveTickets_1.Selected.ID,Comments:RichTextEditor1.HtmlText & User().FullName & " - " & Now() }); ResetForm(Form2);Reset(Gallery3);
With(
{records:'IT Helpdesk Comments'},
ForAll(Sequence(CountRows(records)),Patch(Last(FirstN(records, Value)), {rowNumber: Value}))
)

 

Then comes the part where the Like Icon Onselect property code is being patched 

 

Patch(
 'IT Helpdesk Comments',
 Defaults('IT Helpdesk Comments'),
 {
 LikesID:ThisItem.LikesID,
 CreatorEmail:User().Email
 }
)

 

Display mode property of the Like icon 

 

With(
 {
 wFilter: 
 Filter(
 'IT Helpdesk Comments', 
 CreatorEmail = User().Email &&
 LikesID = ThisItem.LikesID
 )
 },
 If(
 CountRows(wFilter)>0,
 DisplayMode.Disabled,
 DisplayMode.Edit
 )
)

 

Text property of the Label where number of likes counter is being shown 

 

 

With(
 {
 LFilter:
 Filter(
 'IT Helpdesk Comments',
 LikesID=ThisItem.LikesID
 )
 },
 If(
 CountRows(LFilter)>1,
 Text(CountRows(LFilter)) & " people likes this ",
 CountRows(LFilter)=1,
 "One Person likes this ",
 "Be the first to like this "
 )
)

 

Then here is the Onselect property of the Label of Number of likes 

 

With(
 {
 wFilter: 
 Filter(
 'IT Helpdesk Comments', 
 LikesID = ThisItem.LikesID
 )
 },
 If(
 CountRows(wFilter)>0,
 Set(
 ShowWhoLiked,
 true
 )
 )
)

 

 

Categories:
  • Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at

    So, the error is when you show the number of people who liked your post, right?

     

    If you need additional help please tag me in your reply and please like my reply.
    If my reply provided you with a solution, pleased mark it as a solution ✔️!

    Best regards,
    Gonçalo Nogueira

    Check my LinkedIn!

    Check my User Group (pt-PT)!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Apparently the error is with the numbers that it is showing the number in above picture for the total number of comments and not for the likes of that comment that the users did . 

     

    In a nutshell 124 number is that of total comments which unfortunately should not be . 

     

    Thanks alot for your prompt reply @Nogueira1306 

  • Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at

    Okay, you need to filter the list to count the comments / likes

     

    Something like.

    CountRows(Filter(LIST; TitleOfLikes = ThisItem.Tile))

     

    Here I compare the title of the items with the title of the Item. This has also to do with your logic..

     

    If you need additional help please tag me in your reply and please like my reply.
    If my reply provided you with a solution, pleased mark it as a solution ✔️!

    Best regards,
    Gonçalo Nogueira

    Check my LinkedIn!

    Check my User Group (pt-PT)!

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @Nogueira1306  Should I include this code in the Items property of gallery to be precious ? 

     

    Currently the Item property of Gallery looks like this so where should I patch and include it ? 

    With(
     {
     records:
     Filter(
     'IT Helpdesk Comments',
     CommentsID = Gallery_ActiveTickets_1.Selected.ID
     )
     },
     ForAll(
     Sequence(CountRows(records)), 
     Patch(
     Last(
     FirstN(
     records, 
     Value
     )
     ), 
     {rowNumber: Value}
     )
     )
    )

     

    Thanks a ton

     

  • Nogueira1306 Profile Picture
    7,390 Super User 2024 Season 1 on at

    Maybe...

     

    If you need additional help please tag me in your reply and please like my reply.
    If my reply provided you with a solution, pleased mark it as a solution ✔️!

    Best regards,
    Gonçalo Nogueira

    Check my LinkedIn!

    Check my User Group (pt-PT)!

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Sorry but it's not clear to me your answer @Nogueira1306 .

     

    @BCLS776  @RandyHayes  , @WarrenBelz,  by any chance could you any of you kindly take a look at this post and see if you can figure out a solution ?

     

    Thanks alot

    Arsal Subhan

  • Verified answer
    BCLS776 Profile Picture
    8,994 Moderator on at

    @Anonymous, the advice so far in this thread is trying to help you total up your Likes on a comment, but I think the underlying data structure is flawed.

     

    When a user posts a new comment, a new record is created in the IT Helpdesk Comments table, AND when a comment is "Liked" by any user even more records (rows) are added to the same table due to this code:

    Patch(
     'IT Helpdesk Comments',
     Defaults('IT Helpdesk Comments'),
     {
     LikesID:ThisItem.LikesID,
     CreatorEmail:User().Email
     }
    )

    This creates a table that has some rows that are "comments" and some rows that are "likes", all mixed together into an awful mess that is nearly impossible to handle. You need to change how you handle your data for this app to work better and please clear out your table before you run your app again. You have two options I can see for your app:

    1. If you stick to a single table, you can record the number of likes in a specific column. You will increment or decrement this value depending on the user pressing the "likes" button. This option only tracks the total number of "likes" for a comment - it does not track who added a "like", or if they added more than one "like"
    2. To handle keeping track of who has liked a comment, so you can enforce rules around whether they can add/subtract "likes" you need a second table that stores the records for Likes only. The first table contains comments only. The second table will relate to the first table through a common column: The ID of the comment. In that way you can use the CommentsID to LookUp() or Filter() the second table for things such as: total number of likes and who has recorded a "like" on a particular comment.

    I think you want to do Option 2, so start out by making that second table and adjusting your code to store all records of Likes in that one only. Make sure you always store the CommentsID with each record in that table.

     

    Then things will start to get easier for you, and for those users helping you out on here 😉

     

    Bryan

     

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @BCLS776  the tricked worked ! 

     

    I tried the second option by creating another Sharepoint list and doing all the necessary things that you suggested to and it worked out but the only problem I am having are the delegations errors which I got from lookup field for the Like Icon , could you kindly provide a solution for the delegation warning to be removed . 

     

    If
    (
     IsBlank(
     
     LookUp(
     
     'IT comments like',
     LikedBy.Email = User().Email And
     CommentsID.Id = ThisItem.ID
    
     )
     ),
     DisplayMode.Edit,
     DisplayMode.Disabled
    )

     

    Arsal_1-1631128500103.png

     

    Label with number of likes also show Delegation errors 

     

    With(
     {
     LFilter: Filter(
     'IT comments like',
     Text(CommentsID.Id) = Text(ThisItem.ID)
     )
     },
     If(
     CountRows(LFilter) > 1,
     Text(CountRows(LFilter)) & " people likes this ",
     CountRows(LFilter) = 1,
     "One Person likes this ",
     "Be the first to like this "
     )
    )

     

     

    Arsal_2-1631128743514.png

     

    The Tooltip property of Number of likes label 

     

    Concat(
    
     Filter
    (
     'IT comments like',
     CommentsID.Id = ThisItem.ID
    ),LikedBy.DisplayName,",")
    

     

    Arsal_3-1631128822773.png

     

     

  • BCLS776 Profile Picture
    8,994 Moderator on at

    That delegation error should clear up with another With() statement:

     

    With( 
     {aLookup: LookUp(
     'IT comments like',
     LikedBy.Email = User().Email And
     CommentsID.Id = ThisItem.ID)
     },
    
     If(
     IsBlank(aLookup),
     DisplayMode.Edit,
     DisplayMode.Disabled
     )
    )
  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @BCLS776 (Bryan) unfortunately I tried with , WITH () statement but apparently there are still delegation warning showing and thats where I cant figure out why , because when I try this with lookup function it always gives me delegation warnings. The error is *lookup() part of the formula might not work properly on large dataset* and also the highlighted part of formula which is CommentsID.id on large data sets . I will be sure to have large data sets in future so I kindly require help in this case 🙂 

     

    Arsal_0-1631176196543.png

     

    Thank you 

    Arsal 

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 397 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 354

#3
WarrenBelz Profile Picture

WarrenBelz 232 Most Valuable Professional

Last 30 days Overall leaderboard