I have a table for which I am trying to get the most recent record only for each Id according to the created column
ClearCollect(TestList,
{Id: 1, created: 1, desc: "Lorem"},
{Id: 2, created: 3, desc: "Ipsum"},
{Id: 2, created: 2, desc: "Dolar"},
{Id: 3, created: 4, desc: "Sit"},
{Id: 1, created: 4, desc: "Amet"})
I thought I could group the table, sort each resulting table by the created column, keep the first record and then ungroup again.
ClearCollect(filteredList,
Ungroup(
ForAll(
GroupBy(TestList, "Id", "Result"),
{Id: ThisRecord.Id, Result: First(Sort(ThisRecord.Result, created, SortOrder.Descending))}),
"Result")
)
However, the Ungroup function doesn't seem to be ungrouping the table in the results column and I am left with a grouped table:
Any help much appreciated!
With regards to the SharePoint issue and using a data table control, you can just set the items property of the data table control to the formula that I posted. If you use the AddColumns/First syntax, you can retrieve your Result.x Result.y, Result.z columns.
Hello @pleasehelpme2 ,
"Ungroup()" doesn't work because it's expecting a table, but "Result" here is a record.
I've written another formula, can you try and see how it goes:
ForAll(
GroupBy(
testList;
"ID";
"Grouped"
);
AddColumns(
First(
Sort(
ThisRecord.Grouped;
Created;
SortOrder.Descending
)
);
"ID";
ID
)
)
The issue now is that if I set my table items to
Ungroup(
ForAll(
GroupBy(TestList, "Id", "Result"),
{Id: ThisRecord.Id, Result: First(Sort(ThisRecord.Result, created, SortOrder.Ascending))}),
"Result")
it only allows me to add two fields: Id and Result, when really I need to be able to display Result.x Result.y, Result.z etc.
So I suppose I go back to my first question, which is, why doesn't the ungroup work?
replace name of test list with name of your SharePoint list and change names of the columns to match SharePoint List columns and you will be ok
Thanks for your answers. I actually want to show this in a table, and TestList is a sharepoint list. How can I do this?
Alternatively, you could also extract the required details by calling AddColumns and referencing the first Result row.
ClearCollect(filteredList,
AddColumns(GroupBy(TestList,"Id","Result"),
"created",First(Sort(Result,created)).created,
"desc",First(Sort(Result,created)).desc
)
)
here :
ClearCollect(TestList,
{Id: 1, created: 1, desc: "Lorem"},
{Id: 2, created: 3, desc: "Ipsum"},
{Id: 2, created: 2, desc: "Dolar"},
{Id: 3, created: 4, desc: "Sit"},
{Id: 1, created: 4, desc: "Amet"});
ClearCollect(filteredList,
Ungroup(
ForAll(
GroupBy(TestList, "Id", "Result"),
{Id: ThisRecord.Id, Result: First(Sort(ThisRecord.Result, created, SortOrder.Ascending))}),
"Result")
)
in gallery :
and labels You refer like this :
Hope that helps
WarrenBelz
223
Most Valuable Professional
MS.Ragavendar
110
stampcoin
80