I have an excel and I need to extract data for last 7 consecutive days and if data for any day is not available it should not be filtered. for example Today is 30th and from last 7 days data is available for 29th, 26th,25th, and 24th. the output should have data of 29th date only because consecutive 28th is not available so it should miss all other dates like 26,25,and 24.
Similarly if data is available for 29,28,27 also then it should pick data for all dates
Find one of many approaches with the strategy of calculating the filter list
Lets also ask one of my RPA Team members @kumar.varun2 for alternates or optimizations
as the found dates are ordered we do need the first date for sure and ommit it for the evaluation
Then we check for each date if it is the same date as the first date (we ommited)
therefore we are using -1 - the sequence loop counter (0 for first,1 for second …)
So we can detect the series and will prepend the ommited first element
On the last step we use the calculated arrFilterDates for filtering the origin datatable:
dtFiltered =
(From d In dtData.AsEnumerable
Let dp = CDate(d("Update Date").toString.Trim).Date
Where arrFilterDates.Contains(dp)
Select r = d).CopyToDataTable
Feel free to decompose the LINQ parts into essential activities