I am trying to display the values of ApmaksasApmers
(which is a Reference Value) which are closest to DateToCompare
in comparison to GivenDate
For example:
DateToCompare
=01.01.2022 and 01.01.2021
and GivenDate
= 01.03.2022
I am trying to get the values which come from date 01.01.2022
Here is my code:
vm.ApmaksasApmērs.LookupSource = _nolasītMaksājumusQuery.Nolasīt()
.OrderBy(x => x.DateToCompare.Value > vm.GivenDate.Value ? vm.GivenDate.Value - x.DateToCompare.Value : x.DateToCompare.Value - vm.GivenDate.Value)
.Select(x => new KeyValuePair<Guid?, string>(x.Id, x.ApmaksasApmērs +" (" + x.PersonasLīdzmaksājumsProcentos + "%)".ToString())) ;
Here I am geting an error of Name:[ApmaksasApmērs],Type:[ReferenceValue],Message:[Don't currently support idents of type TimeSpan]
Is there a better way of doing this? Thanks in advance
2
Answers
Here is what I did :
Create a list for all of the elements:
Find the max value from the list:
Find all of the elements where
MaxDate == DateToCompare
:Hi if DateToCompare is an array then we compare the absolute value of difference between each el with the given date and when the value is lowest that’s the closest date
Here is how