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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Previous date of occurrence

Hello

 

I'm trying to get the date of the last occurrence.

 

Example

Employee IDDate of visitDiscipline
19/1/2021RN
19/6/2021CNA
19/10/2021RN
19/25/2021RN
29/5/2021RN
29/10/2021RN

 

 

What I Need RN Last Visit Date or Example Column #4

 

Employee IDDate of visitDisciplinePrevious occurrence
19/1/2021RN 
19/6/2021CNA 
19/10/2021RN9/1/2021
19/25/2021RN9/10/2021
29/5/2021RN 
29/10/2021RN9/5/2021

 

 

 

the ultimate goal is to find the number of days between each visit, but I thought I needed to find the previous occurrence first. then perform a datediff measurement

Thanks in advance

8 REPLIES 8
Anonymous
Not applicable

Hi @Anonymous,

Did these suggestions help with your scenario? if that is the case, you can consider Kudo or accept the helpful suggestions to help others who faced similar requirements.

If these also don't help, please share more detailed information to help us clarify your scenario to test.

How to Get Your Question Answered Quickly 

Regards,

Xiaoxin Sheng

Anonymous
Not applicable

Hi, nope. None of the suggestions helped get what I was looking for. 

Anonymous
Not applicable

Hi @Anonymous,

So you mean you need a calculated column to do some calculations in direct query mode? AFAIK, most DAX functions have been limited to use in calculated column/table if you are working with 'direct query' mode.

What type of data source are you worked on? If it supports advanced queries, you can try to add a custom column in the query.

Regards,

Xiaoxin Sheng

ERD
Community Champion
Community Champion

Hi @Anonymous ,

Did you try to create a measure? For example,

days = 
VAR currentEmpID = MAX ( T[EmployeeID] )
VAR currentDisc = MAX ( T[Discipline] )
VAR currentDate = MAX ( T[VisitDate] )
VAR prevDate =
    CALCULATE (
        MAX ( T[VisitDate] ),
        FILTER (
            ALL ( T ),
            T[EmployeeID] = currentEmpID
                && T[Discipline] = currentDisc
                && T[VisitDate] < currentDate
        )
    )
RETURN
    COALESCE ( DATEDIFF ( prevDate, currentDate, DAY ), 0 )

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!

CNENFRNL
Community Champion
Community Champion

Previous occurrence = 
MAXX(
    FILTER(
        VISIT,
        VISIT[Employee ID] = EARLIER( VISIT[Employee ID] )
            && VISIT[Discipline] = EARLIER( VISIT[Discipline] )
            && VISIT[Date of visit] < EARLIER( VISIT[Date of visit] )
    ),
    VISIT[Date of visit]
)

Screenshot 2021-10-01 211746.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Anonymous
Not applicable

Can't use MAXX in Direct Query either

callaott_0-1633120255883.png

 

 

parry2k
Super User
Super User

@Anonymous try adding this column 

 

Prev Visit Date = 
VAR __d = Visit[Visit Date]
RETURN
IF ( Visit[Discipline] = "RN",
    CALCULATE ( 
        MAX ( Visit[Visit Date] ), 
        Visit[Visit Date] < __d, 
        Visit[Employee ID] = EARLIER ( Visit[Employee ID] ) 
    ) 
)

 

Follow us on LinkedIn

 

Check my latest blog post The Power of Using Calculation Groups with Inactive Relationships (Part 1) (perytus.com) I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

 

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Anonymous
Not applicable

This is the error message i am receiving. I am unable to change from DirectQuery.

callaott_0-1633111557272.png

 

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!

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