I want to create one chart which shows number of post by each team member in the channel. I am using power apps in teams. Chart should have number of post on y-axis and name of person on x-axis.
// Get Team's groupId
UpdateContext(
{
varGroupId: LookUp(
MicrosoftTeams.GetAllTeams().value,
displayName = "Your Team's display name"
).id
}
);
// Get Team's channelId
UpdateContext(
{
varChannelId: LookUp(
MicrosoftTeams.GetChannelsForGroup(varGroupId).value,
displayName = "Your channel's display name"
).id
}
);
// Get all messages from channel
ClearCollect(
RawChannelMessages,
MicrosoftTeams.GetMessagesFromChannel(
varGroupId,
varChannelId
).value
);
// Get all distinct users from channel messages, init MessageCount column
ClearCollect(
DistinctUsers,
AddColumns(
Filter(
Distinct(
RawChannelMessages,
from.user.displayName
),
!IsBlank(ThisRecord.Value)
),
MessageCount,
0
)
);
// Update distinct user list with their message counts
ForAll(
RawChannelMessages,
With(
{messageUserDisplayName: ThisRecord.from.user.displayName},
With(
{
existingUser: LookUp(
DistinctUsers,
Value = messageUserDisplayName
),
existingUserMessageCount: LookUp(
DistinctUsers,
Value = messageUserDisplayName
).MessageCount
},
Patch(
DistinctUsers,
existingUser,
{MessageCount: existingUserMessageCount + 1}
)
)
)
);
Note: Be sure to change Your Team's display name and Your channel's display name to their respective values.
This will create a table called DistinctUsers which has two columns. Value, which is the name of all distinct users who have made posts in your channel. MessageCount, which is the number of posts each distinct user has posted.
Here is an example of DistinctUsers:
MessageCount | Value
1 | Jon, Doe
3 | Al, Dente
2 | First, Last