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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Bring back single value from a list based on a filter condition

Hello,

 

I have two tables:

 

Users

Name      Id

bob1
Joe2

 

Results

Id            UserId    CreatedOn    TestName  Passed

1101/02/2017"Test1"False
2101/04/2017"Test1"True
3101/08/2017"Test1"True
4101/02/2017"Test2"False
5204/04/2017"Test1"False
6204/03/2017"Test1"True
7205/03/2017"Test2"False

 

I'm trying to write a DAX query to retrieve the result of the latest record for a user with a filter for a certain test name. In this example, I want to bring the "Passed" column back for Bob where test = "test1". I could filter the table using a CALCULATE and applying a TestName = "Test1" but I have no idea how I would then bring back the result for row 3 (the one with the highest date). 

 

Does anyone know the best way to approach this problem?

 

Many thanks,

 

Chris

 

 

3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

 

You can try to use below measure to get last date status based on user id and test:

 

Measure =
CALCULATE (
    LASTNONBLANK ( Table1[Passed], [Passed] ),
    VALUES ( Table1[UserID] ),
    VALUES ( Table1[Text] ),
    LASTDATE ( VALUES ( Table1[Date] ) )
)

9.PNG

 

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Anonymous
Not applicable

Hi @Anonymous,

 

Try this measure and create a table visual with User and the measure to see if each user passed the test or not:

Measure =
CALCULATE (
    VALUES ( Table_Passed[Passed] );
    Table_Passed[Test Name] = "Test1";
    LASTDATE ( Table_Passed[CreateOn] )
)

Regards.

Anonymous
Not applicable

Hi FelipeLima,

 

Thanks for the response.

 

Unfortunately I'm getting the below:

 

"Something's wrong with one or more fields: (Users) A date column containing duplicate dates was specified in the call to function 'LASTDATE'. This is not supported.

 

I believe this is because the same date can appear multiple times for a user.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.