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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
jayjay0306
Helper III
Helper III

DAX - How to get the latest date in at table?

Hi people,

I hope you ca help me with a small challange:

I have table (visualization) which shows a customer survey (example with 2 customers):

exhibit 1.PNG

What I need to extract is simply the latest "answer" from each question, from each customer.

I have tried to make the following measure "Lastest survey date":

 

 

Latest Survey Date = 
VAR GroupByCustCode= ALLEXCEPT ( Customer, Customer[Customer Code])
RETURN
CALCULATE ( MAX ( 'Surveys'[survey_date_key] ),GroupByCustCode)

 

 

But this gives me the result:

exhibit 2.PNG

What I need is this:

exhibit 3.PNG

 

Can someone please show me what I am missing in my measure?

Thanks.

 

Br,

JayJay0306

 

6 REPLIES 6
v-chenwuz-msft
Community Support
Community Support

Hi @jayjay0306 

 

You need create a measure to replace the field Answer with this

Answer_m =
CALCULATE(
    MAX( 'Customer'[Answer] ),
    FILTER( 'Customer', [survey_date_key] = [Latest Survey Date] )
)

 

Or change your latest survey date to this:

Latest Survey Date =
VAR GroupByCustCode =
    ALLEXCEPT( Customer, Customer[Customer Code] )
VAR _last =
    CALCULATE( MAX( 'Customer'[survey_date_key] ), GroupByCustCode )
VAR _answer =
    CALCULATE(
        MAX( 'Customer'[Answer] ),
        FILTER(
            ALL( 'Customer' ),
            [Customer Code] = MAX( 'Customer'[Customer Code] )
                && [Business Name] = MAX( 'Customer'[Business Name] )
                && [Question] = MAX( 'Customer'[Question] )
                && [survey_date_key] = _last
        )
    )
RETURN
    IF( MAX( 'Customer'[Answer] ) = _answer, _last, BLANK() )

I put my pbix file in the attachment you can reference.

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi Team _ chenwu zhu,

Thanks a lot. This is exactly the result I am looking for. However, I am afraid, I haven't been specific enough. The problem is, that my datamodel consists of several tables. I have tried to edit your script to fit my datamodel:

Latest Survey Date = 
VAR GroupByCustCode =
    ALLEXCEPT( Customer, Customer[Customer Code] )
VAR _last =
    CALCULATE( MAX( 'Executed Survey'[Survey Completion Date] ), GroupByCustCode )
VAR _answer =
    CALCULATE(
        MAX( 'Executed Survey'[Answer] ),
        FILTER(
            ALL( 'Customer' ),
            [Customer Code] = MAX( 'Customer'[Customer Code] )
                && [Business Name] = MAX( 'Customer'[Business Name] )),
        FILTER(
            ALL( 'Question Attributes' ),
            [Question] = MAX( 'Question Attributes'[Question] )),
        
        FILTER(
            ALL('Executed Survey'),
                'Executed Survey'[Survey Completion Date] = _last
        )
    )
RETURN
    IF( MAX( 'Executed Survey'[Answer] ) = _answer, _last, BLANK() )

but unfortunately I get my original result:

Capture1234.PNG

Can you see what I do wrong?

thanks.

Br,

Jayjay0306

Hi @jayjay0306 , maybe your have Incorrect relationship or no relationships beteween these tables.

or  crossjoin these tablas into one table witch table like the table you show .

Can you share you pbix file after removing the sensitive information.

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

AllisonKennedy
Super User
Super User

@jayjay0306  If you don't put the Answer column in your visual you could try using LASTDATE or something similar:

 

Latest Answer =
CALCULATE ( SELECTEDVALUE ( 'Surveys - Executed Survey Attributes'[Answer] ),LASTDATE(  'Surveys - Executed Survey Attributes'[Survey Date] ) )


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Hi AllisonKennedy,

Thanks, but I do need the Answer column in the table. 😞

Br,

Jayjay0306

@jayjay0306  Can you share your data model please? We need all the info to be able to help effectively. Which table do each of these values come from?


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.