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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
atjt217
Helper III
Helper III

Last order date by Customer

Hello, 

I would like to ask for help figuring out which formula to use on my report. I got 2 tables where i need to get the last order date from the order table to be able to see when is the last time our Customer made an order: 

 

SampleSample

I appreciate your help! 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @atjt217 ,

All DAX functions are supported for DirectQuery models. However, not all functions are supported for all formula types. Some functions like CALCULATE are supported in measure and query formulas only. For details: DAX Formula Compatibility in DirectQuery Mode

 

In your scenario, please new a measure rather than creating a calculated column using above formula.

 

Please refer to my pbix file to see if it helps you.

Create a measure.

 

Measure =
CALCULATE (
    MAX ( 'Sheet2$'[Date] ),
    FILTER (
        ALL ( 'Sheet2$' ),
        'Sheet2$'[Customer ID] = SELECTEDVALUE ( 'Sheet2$'[Customer ID] )
    )
)

 

Then create relationships between the tables.

vpollymsft_0-1649730404098.png

vpollymsft_1-1649730418669.png

 

If I have misunderstood your meaning, please provide your desired output with more details.

 

Best Regards

Community Support Team _ Polly

 

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

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @atjt217 ,

All DAX functions are supported for DirectQuery models. However, not all functions are supported for all formula types. Some functions like CALCULATE are supported in measure and query formulas only. For details: DAX Formula Compatibility in DirectQuery Mode

 

In your scenario, please new a measure rather than creating a calculated column using above formula.

 

Please refer to my pbix file to see if it helps you.

Create a measure.

 

Measure =
CALCULATE (
    MAX ( 'Sheet2$'[Date] ),
    FILTER (
        ALL ( 'Sheet2$' ),
        'Sheet2$'[Customer ID] = SELECTEDVALUE ( 'Sheet2$'[Customer ID] )
    )
)

 

Then create relationships between the tables.

vpollymsft_0-1649730404098.png

vpollymsft_1-1649730418669.png

 

If I have misunderstood your meaning, please provide your desired output with more details.

 

Best Regards

Community Support Team _ Polly

 

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

VahidDM
Super User
Super User

Hi @atjt217 

 

You can add a new column with dax to the Customer Table with this formula:

LastOrder = 
CALCULATE (
    MAX ( 'Order Table'[Date] ),
    FILTER (
        ALL ( 'Order Table' ),
        'Order Table'[CustomerID] = EARLIER ( 'Customer Table'[CustomerID] )
    )
)

 

Output:

VahidDM_0-1649372595999.png

 

 

 

 

Sample file attached, please download.

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Hello VahidDM, 

 

I tried it out but im getting this error message: 

"Function 'CALCULATE' is not allowed as part of calculated column DAX expressions on DirectQuery models."  

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!

December 2024

A Year in Review - December 2024

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