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

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

Reply
Anonymous
Not applicable

Max of a column based on two other Columns

Hi,

 

I want to find the max of the "Sold" column based on the max "ReadingDate" for each product category. Please, I would like to use DAX for this. For example, Beans would return 9 as the max based on the date time field. Thanks so much.

 

 

ReadingDatePrroductSold
7/1/2020 : 7:37:44 PMBeans1
7/1/2020 : 7:45:29 AMBeans0
7/3/2020 : 7:37:44 PMRice0
7/1/2020 : 5:37:44 AMFruit3
7/16/2020 : 7:37:44 AMRice0
7/5/2020 : 10:00:44 AMYam4
7/16/2020 : 04:37:44 PMYam5
7/8/2020 : 11:37:14 PMFruit3
7/1/2020 : 5:37:13 AMYam1
7/15/2020 : 7:37:44 PMFruit0
7/4/2020 : 2:02:12 PMBeans1
7/5/2020 : 7:37:44 AMBeans0
7/5/2020 : 7:37:44 PMRice2
7/10/2020 : 5:27:09 PMBeans9
7/16/2020 : 7:37:44 PMRice0
7/16/2020 : 6:20:11AMRice3
7/17/2020 : 7:37:44 PMRice4
7/16/2020 : 12:37:44 PMFruit8
7/16/2020 : 9:37:40 AMFruit9
1 ACCEPTED SOLUTION
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this expression in a measure.  Note that I had to change your ReadingTime column in the query editor to replace " : " with " ", so that I could change it to DateTime type.  You will need to change the name of the table to your actual name.

 

Latest Count =
VAR maxdatetime =
    MAX ( 'Product'[ReadingDate] )
RETURN
    CALCULATE ( MAX ( 'Product'[Sold] ), 'Product'[ReadingDate] = maxdatetime )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

Please try this expression in a measure.  Note that I had to change your ReadingTime column in the query editor to replace " : " with " ", so that I could change it to DateTime type.  You will need to change the name of the table to your actual name.

 

Latest Count =
VAR maxdatetime =
    MAX ( 'Product'[ReadingDate] )
RETURN
    CALCULATE ( MAX ( 'Product'[Sold] ), 'Product'[ReadingDate] = maxdatetime )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Hi @mahoneypat 

 

 

Thanks for you prompt response. I ran your code but it only gave me one value for all the products. Looking at your code, i'm assuming that Product is the name of the table but at what point did you factor in the fact that there is a product category column containing (Beans , rice etc) in the data? I'm guessing that's why it didn't give the wanted result. Thanks.

Anonymous
Not applicable

@mahoneypat 

 

I am so SORRY. Your code worked like a charm. I was in the wrong table that's why and i didn't need to change the colon on the datetime field to space and it still worked. Thanks so much. 🤗

Anonymous
Not applicable

@Fowmy 

 

Hi! Is there a way around this? Please, i need your help. thanks

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!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

Top Solution Authors
Top Kudoed Authors