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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Advanced Date Filtering using DAX

Good day, 

 

I have data quesry consists of number of Execel files. 

 

Query has colunms "SHIP NAME" and "Date of Reports". Some of the "SHIP NAME" repeats various times with different "DATES". While ago I was interested to filter out only latest date lines for visuals and used following measures and custom colums:

 

1) Max Date = calculate(max('RNA Date of Report'[Date of Report].[Date]), filter('RNA Date of Report', 'RNA Date of Report'[Ships Name]=EARLIER('RNA Date of Report'[Ships Name])))
 
2) IsLatest = If('RNA Date of Report'[Date of Report].[Date]='RNA Date of Report'[Max Date].[Date],"Latest Audit", "All Audits")
 
Since there are much more lines in the quesry for the same "SHIPS NAME" - I'm looking for possibility to create filter for previous to last date. Some have 2 lines, but some have 3+ (dates). Any ideas? 
 
Thanks
Aleks 
 
 
5 REPLIES 5
smpa01
Community Champion
Community Champion

@Anonymous  can you provide sample data


========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
• Plotting Live Sound: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================
Anonymous
Not applicable

AleksandrMe_0-1633524562705.png

 

VahidDM
Super User
Super User

Hi @Anonymous 

 

Can you add a sample of your data and result here?

For the Max Date measure, you can use LASTDATE ('RNA Date of Report'[Date of Report])
Max Date=LASTDATE ('RNA Date of Report'[Date of Report])

and then if you want to use that in the other measure, you can add a variable in your measure like this:

 

IsLatest =
VAR _MaxDate =
    CALCULATE (
        LASTDATE ( 'RNA Date of Report'[Date of Report] ),
        ALLEXCEPT ( 'RNA Date of Report', 'RNA Date of Report'[Ships Name] )
    )
RETURN
    IF (
        'RNA Date of Report'[Date of Report] = _MaxDate,
        "Latest Audit",
        "All Audits"
    )

 

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

Appreciate your Kudos✌️!!

Anonymous
Not applicable

Good day, 

 

Thnaks for reply. What I'm looking for is the new measure which will filter out date previous to last. The above one is not helping me, or I;m doing something wrong.

 

Kidn Regards

Aleks 

 

Anonymous
Not applicable

Raally looking for solution how to use DAX function to recognize LATEST, Previous Date for each line. 

 

I use below functions to recognize latest, but cannot progress more ("all audit"s need to be broken down on more conditions)

 

1) Max Date = calculate(max('RNA Date of Report'[Date of Report].[Date]), filter('RNA Date of Report', 'RNA Date of Report'[Ships Name]=EARLIER('RNA Date of Report'[Ships Name])))
 
2) IsLatest = If('RNA Date of Report'[Date of Report].[Date]='RNA Date of Report'[Max Date].[Date],"Latest Audit", "All Audits")
 
Any more ideas? 
 
THnaks
Aleks 
 
#help needed

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.