Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Creative_tree88
Helper IV
Helper IV

Finding a value between two dates

Hi all - I need to find a value, most likely using lookup function??  Not sure.  But the value is between a range, consisting of two dates.  However, the key I'm using to lookup, has multiple values attached to it so I can't just use the 'KEY' on it's own in this example, I need to specifically find the corresponding value in between the date range (Admission and Discharge).

I've attached a link to the sample data (really cut down but is representative of overall cohort).  Occasionally there is no discharge date, so will just need to use admission date only.  For your reference, the correct lookup is identified in my sample date as yellow filled, for ease to identify.

 

Any ideas?  I can't just use a lookup, as there are multiple values, but also HAS to be within the range given.

 

Thanks to @BIswajit_Das you helped me in the first request like this, but I didn't take into account the multiple values in my sample data, and hence the need to locate the correct value in a specific date range, between the admission date and discharge date.

 

Appreciate your help - this one has really perplexed me!!!!  

 

Sample Data 

1 ACCEPTED SOLUTION
BIswajit_Das
Solution Supplier
Solution Supplier

Hello @Creative_tree88
PB3.png
Try this DAX out
(Here 'Table1' is 'Data' & 'Table2' is 'Lookup Data')

#EXAM2 =
VAR _start = 'Table1'[Admission]
VAR _end = 'Table1'[Discharge]
VAR _key = 'Table1'[KEY]

VAR _singleDateExam =
    LOOKUPVALUE(
        'Table2'[Exam],
        'Table2'[Event Date].[Date], _start,
        'Table2'[KEY], _key
    )

VAR _multiDateExams =
    CALCULATE(
        CONCATENATEX(
            FILTER(
                'Table2',
                'Table2'[Event Date].[Date] >= _start &&
                'Table2'[Event Date].[Date] <= _end &&
                'Table2'[KEY] = _key
            ),
            'Table2'[Exam],
            ", "
        )
    )

RETURN
IF(
    ISBLANK(_end),
    _singleDateExam,
    _multiDateExams
)
If you found this information useful, please consider marking it as the accepted solution.
Thanks & Regrads...

View solution in original post

5 REPLIES 5
BIswajit_Das
Solution Supplier
Solution Supplier

Hello @Creative_tree88
PB3.png
Try this DAX out
(Here 'Table1' is 'Data' & 'Table2' is 'Lookup Data')

#EXAM2 =
VAR _start = 'Table1'[Admission]
VAR _end = 'Table1'[Discharge]
VAR _key = 'Table1'[KEY]

VAR _singleDateExam =
    LOOKUPVALUE(
        'Table2'[Exam],
        'Table2'[Event Date].[Date], _start,
        'Table2'[KEY], _key
    )

VAR _multiDateExams =
    CALCULATE(
        CONCATENATEX(
            FILTER(
                'Table2',
                'Table2'[Event Date].[Date] >= _start &&
                'Table2'[Event Date].[Date] <= _end &&
                'Table2'[KEY] = _key
            ),
            'Table2'[Exam],
            ", "
        )
    )

RETURN
IF(
    ISBLANK(_end),
    _singleDateExam,
    _multiDateExams
)
If you found this information useful, please consider marking it as the accepted solution.
Thanks & Regrads...

@BIswajit_Das I'm now getting a message on this:

Column reference to 'Event Date' in table 'Activity' cannot be used with a variation 'Date' because it does not have any.

Any idea why this would be happening?  Obviously now returning error in the column.  Many thanks!

@BIswajit_Das - I've just tried to use this same method on an updated table, based exactly on the previous one, but it's now saying 'ERROR - A table of multiple values was supplied where a single value was expected'

I really do not understand as I have not changed anything at all...any advice at all?   Thank you.

Hello @Creative_tree88 
I think you're creating a measure/table in which you are returning a column of multiple values.


"ERROR - A table of multiple values was supplied where a single value was expected" this error
occurs in DAX when a function expects a single value but instead receives a table or multiple values.

 

Create a calculated column and It Suppose to work
If it does not work then attach the demo data i'll try to fix the DAX

Thanks & Regards...

@BIswajit_Das I added a new column and copied the DAX into the formula bar at the top.  Did it the same way as previously.  For some reason it's not working unlike the previous month when it worked perfectly.  I'm trying to understand if I have done something differently to last time...but so far am a bit confused as to why all of a sudden it's stopped working...

 

I'll send you some demo data.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.