Async Function GetMaxValuePerGroup(siteUrl As String, username As String, password As String, listName As String, field1Name As String, field2Name As String) As Task
Dim credentials As String = Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{password}"))
Using client As New HttpClient()
client.DefaultRequestHeaders.Authorization = New System.Net.Http.Headers.AuthenticationHeaderValue("Basic", credentials)
Dim endpointUrl As String = $"{siteUrl}/_api/web/lists/getbytitle('{listName}')/items?$select={field1Name},{field2Name}&$orderby={field1Name}&$top=5000"
Dim response As HttpResponseMessage = Await client.GetAsync(endpointUrl)
If response.IsSuccessStatusCode Then
Dim responseContent As String = Await response.Content.ReadAsStringAsync()
Dim json As JObject = JObject.Parse(responseContent)
Dim items As JArray = json("value")
' 列1でグループ化して列2の最大値を求める
Dim groupedData = From item In items
Group item By Key = item(field1Name).ToString() Into Group