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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
mcinnisbr
Advocate I
Advocate I

How to label max date and previous date (for all months) calculated column.

Hi, not sure if this can be done in calculated column.  or a measure.  Confused trying to figure it out.  

 

I have survey data with completion dates for multiple months. I want to label (in a calculated column) the max date and previous date for each month.  If it is not the max date, label as previous.

 

NameCompletion dateMaxdate
Canada22/03/2021 4:31:41 PMMax
Canada21/03/2021 9:04:09 AMPrevious
USA23/03/2021 9:05:48 AMMax
USA22/03/2021 12:07:39 PM

Previous
Canada15/02/2021 4:31:41 PMMax
Canada14/02/2021 9:04:09 AMPrevious
USA16/02/2021 9:05:48 AMMax
USA14/02/2021 12:07:39 PMPrevious

 

Essentially, i'm looking to represent my data (tied to those max/previous dates) as a clustered chart for those different monthly submissions.

mcinnisbr_1-1616680095927.png

 

Thanks if any help can be had. 

 

 

1 ACCEPTED SOLUTION
ERD
Community Champion
Community Champion

Hello @mcinnisbr ,

You can try this code for your calculated column:

Maxdate = 
var currentName = 'Table'[Name]
var currentMonth = MONTH('Table'[CompletionDate])
var currentDate = 'Table'[CompletionDate]
var maxDate = 
CALCULATE(  
    MAX('Table'[CompletionDate]),
    FILTER('Table', 
        'Table'[Name] = currentName && 
        MONTH('Table'[CompletionDate]) = currentMonth)
   
)
return IF('Table'[CompletionDate] = maxDate, "max", "previous")

 

Did I answer your question? Mark my post as a solution!

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!

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hello @mcinnisbr,

 

Can you tell me if you built this graphic on Power BI??? If so, could you let me know how?

MSA_BB123_0-1641834745594.png

 

ERD
Community Champion
Community Champion

Hello @mcinnisbr ,

You can try this code for your calculated column:

Maxdate = 
var currentName = 'Table'[Name]
var currentMonth = MONTH('Table'[CompletionDate])
var currentDate = 'Table'[CompletionDate]
var maxDate = 
CALCULATE(  
    MAX('Table'[CompletionDate]),
    FILTER('Table', 
        'Table'[Name] = currentName && 
        MONTH('Table'[CompletionDate]) = currentMonth)
   
)
return IF('Table'[CompletionDate] = maxDate, "max", "previous")

 

Did I answer your question? Mark my post as a solution!

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!

mcinnisbr
Advocate I
Advocate I

I've attempted to scrap through this using abit of your suggestion and another.   It works.  But, it's not tagging the previous month (as you see with the Canada/usa example) with it's 'max' value.  It's just max for Canada for all months until it gets to the next name.
myMaxval =
VAR CurrentName ='table'[Name]
VAR _maxdate1 = MAXX(
FILTER(ALL('table'),'table'[Name] = CurrentName ),'table'[Completion time])
 
RETURN
IF('table'[Completion time]=_maxdate1,"max","Previous")
 
mcinnisbr_0-1616703000113.png

 

Anonymous
Not applicable

Column = VAR _maxdate = CALCULATE(MAX('Table'[Completion date]),ALLEXCEPT('Table','Table'[Name],'Table'[Completion date].[Year],'Table'[Completion date].[MonthNo])) RETURN IF('Table'[Completion date]=_maxdate,"max","Previous")

I understand this.  I'm getting an error (or the column measure error) when attempting to add the .[Year] and .[MonthNo].  I don't understand how to add this part?  Do i have to attach a date table column to this?

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.