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

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

Reply
davidibi4524
Frequent Visitor

help with max value

hi

i have a table from SQL server that contain:

customer number ---- order date

i need to edit the query to get only the max(order curdate)

for each customer.

how can i do it?

thanks.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @davidibi4524 ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. I used the following methods separately to get the latest order date:

1. Create a table visual with Max of Order date

2. Create a measure to get the latest order date

Latest order date =
CALCULATE (
    MAX ( 'Prev_forecast'[Order date] ),
    FILTER (
        'Prev_forecast',
        'Prev_forecast'[CUSTNAME] = SELECTEDVALUE ( Prev_forecast[CUSTNAME] )
            && 'Prev_forecast'[ordname] = SELECTEDVALUE ( 'Prev_forecast'[ordname] )
    )
)

3. Create a calculated table

TableName = 
SUMMARIZE (
    'Prev_forecast',
    'Prev_forecast'[CUSTNAME],
    'Prev_forecast'[ordname],
    "maxordate", CALCULATE ( MAX ( 'Prev_forecast'[Order date] ) )
)

yingyinr_1-1622616165748.png

Best Regards

View solution in original post

9 REPLIES 9
Anonymous
Not applicable

Hi @davidibi4524 ,

I created a sample pbix file(see attachment) for you, please check whether that is what you want. I used the following methods separately to get the latest order date:

1. Create a table visual with Max of Order date

2. Create a measure to get the latest order date

Latest order date =
CALCULATE (
    MAX ( 'Prev_forecast'[Order date] ),
    FILTER (
        'Prev_forecast',
        'Prev_forecast'[CUSTNAME] = SELECTEDVALUE ( Prev_forecast[CUSTNAME] )
            && 'Prev_forecast'[ordname] = SELECTEDVALUE ( 'Prev_forecast'[ordname] )
    )
)

3. Create a calculated table

TableName = 
SUMMARIZE (
    'Prev_forecast',
    'Prev_forecast'[CUSTNAME],
    'Prev_forecast'[ordname],
    "maxordate", CALCULATE ( MAX ( 'Prev_forecast'[Order date] ) )
)

yingyinr_1-1622616165748.png

Best Regards

ERD
Community Champion
Community Champion

Hi @davidibi4524 ,

Do you need a measure? If so, you can use something like this one:

Measure = 
VAR currentCustomer = MAX('T'[Customer])
RETURN
CALCULATE(
    MAX('T'[OrderDate]),
    'T'[Customer] = currentCustomer)

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

thanks but i need it as a table

ERD
Community Champion
Community Champion

@davidibi4524 ,

In case of DAX table:

 

TableName = 
ADDCOLUMNS (
    DISTINCT ( 'T'[Customer] ),
    "@latestDate", CALCULATE ( MAX ( 'T'[OrderDate] ) )
)

DAX query:

EVALUATE
ADDCOLUMNS (
    DISTINCT ( 'T'[Customer] ),
    "@latestDate", CALCULATE ( MAX ( 'T'[OrderDate] ) )
)

 

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

its looks like close to the solution,because now i need to add some more columns and its didnt work for me. i can only add the first column again (custname)

here is a screenshot:

 

davidibi4524_0-1622468329180.png

 

ERD
Community Champion
Community Champion

@davidibi4524 , you need to add an existing column or to calculate something?

If you need to add several columns like 'T'[Customer], then the code will be a bit different:

TableName = 
ADDCOLUMNS (
    SUMMARIZE('T', 'T'[Customer], 'T-main'[AnotherColumn]),
    "@latestDate", CALCULATE ( MAX ( 'T'[OrderDate] ) )
)

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

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Anonymous
Not applicable

Are you looking for a sql query or a dax?

DAX

Anonymous
Not applicable

Try this DAX,

 

Table 2 = SUMMARIZE('Table','Table'[Date],"Max",CALCULATE(max('Table'[Rank])))
 
Thnx

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.