Forum Discussion
Creative_tree88
1 year agoHelper V
Value between Two Dates
Hi - I have the following DAX which is in a calculated column. The issue I'm having is that it's saying there are multiple values where single is expected. Is there any way of adapting this express...
danextian
1 year agoSuper User
The issue lies with using LOOKUPVALUE as it expects a single value to be returned if the optional parameter alternateResult is not specified. This error doesn't occur if using your sample data though.
I'm not sure what should be returned when there are multiple values, as the expectation is that there should only be one result if end is blank. You might need to review your logic. However, if there are indeed two or more results, you could simply return _multiDateCodes as the alternate result.
Value Between Two Dates Lookup =
VAR _start = 'Finance Data'[Sales Letter A Date]
VAR _end = 'Finance Data'[Sales Letter B Date]
VAR _key = 'Finance Data'[KEY]
VAR _singleDateCode =
LOOKUPVALUE (
'Sales Data'[Code],
'Sales Data'[Sales Date], _start,
'Sales Data'[KEY], _key
)
VAR _multiDateCodes =
CALCULATE (
CONCATENATEX (
FILTER (
'Sales Data',
'Sales Data'[Sales Date] >= _start
&& 'Sales Data'[Sales Date] <= _end
&& 'Sales Data'[KEY] = _key
),
'Sales Data'[Code],
", "
)
)
RETURN
IFERROR( singleDateCode, _multiDateCodes )