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
Vnidias
Regular Visitor

Calculated Max Date Column Filtered by Category

Good morning i´m trying to create a max column to set the following condition:

if the max date is the max date from the store, put a flag Y

 

In a measure i did this and worked well, but the user need use this flag as filter.

 

the measure created:

Flag Visited :=

VAR datemax = CALCULATE(MAX('Date'[Date]),FILTER(ALL('Execution Audit KPI'),'Execution Audit KPI'[Audit Store SK] = SELECTEDVALUE('Execution Audit KPI'[Audit Store SK])))

VAR flag = IF(datemax = SELECTEDVALUE('Date'[Date]) ,"Y","N")

return

flag

 

What i need: create the same condition done by measure but by a calculated column

 

My try:

 

flagnova =

var maxdate = CALCULATE(
MAXX(
SUMMARIZE('exec audit','exec audit'[Audit Store SK]),MAX('exec audit'[Start Date SK])
),ALLEXCEPT('exec audit','exec audit'[Audit Store SK]))

return  
IF(maxdate = 'exec audit'[Start Date SK] ,"Y","N")
 
Results from my try
 
It almost worked, but instead to do the max date per month he did the max date in a day level.
 
MicrosoftTeams-image.png
 
 
 
Table Model example:
 
imagem_2022-11-23_113605005.png
 
Could you guys help me with this ?
 
Att.
 
 
 
 
 
 

 

 

 

1 ACCEPTED SOLUTION

Hi @Vnidias 
In this case the easiest appraoch is to first create a YearMonth YYYMM integer data type column

YearMonth = YEAR ( 'exec audit'[Date] ) * 100 + MONTH ( 'exec audit'[Date] )

Then the formula would be

flagnova =
VAR maxdate =
    CALCULATE (
        MAX ( 'exec audit'[Date] ),
        ALLEXCEPT (
            'exec audit',
            'exec audit'[Audit Store SK],
            'exec audit'[YearMonth]
        )
    )
RETURN
    IF ( 'exec audit'[Start Date SK] = maxdate, "Y", "N" )

 

 

 

 

 

View solution in original post

3 REPLIES 3
tamerj1
Super User
Super User

Hi @Vnidias 

please try

flagnova =
VAR maxdate =
CALCULATE (
MAX ( 'exec audit'[Date] ),
ALLEXCEPT ( 'exec audit', 'exec audit'[Audit Store SK] )
)
RETURN
IF ( 'exec audit'[Start Date SK] = maxdate, "Y", "N" )

At the following moment this filtered did partially correct.

When i have two dates in a same month works.

 

ex:
2022-01-10, 

2022-01-15

 

He marks correct.

 

But when the store has more months visited like:

2022-01-10, 

2022-01-15,

2022-02-20

 

Doesnt work properly.

He will put 

 

2022-01-10, N

2022-01-15, N 

2022-02-20, Y

 

What he should do for the same store ID

2022-01-10, N

2022-01-15, Y

2022-02-20, Y

 

 

Hi @Vnidias 
In this case the easiest appraoch is to first create a YearMonth YYYMM integer data type column

YearMonth = YEAR ( 'exec audit'[Date] ) * 100 + MONTH ( 'exec audit'[Date] )

Then the formula would be

flagnova =
VAR maxdate =
    CALCULATE (
        MAX ( 'exec audit'[Date] ),
        ALLEXCEPT (
            'exec audit',
            'exec audit'[Audit Store SK],
            'exec audit'[YearMonth]
        )
    )
RETURN
    IF ( 'exec audit'[Start Date SK] = maxdate, "Y", "N" )

 

 

 

 

 

Helpful resources

Announcements
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.