Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello
I'm trying to get the date of the last occurrence.
Example
Employee ID | Date of visit | Discipline |
1 | 9/1/2021 | RN |
1 | 9/6/2021 | CNA |
1 | 9/10/2021 | RN |
1 | 9/25/2021 | RN |
2 | 9/5/2021 | RN |
2 | 9/10/2021 | RN |
What I Need RN Last Visit Date or Example Column #4
Employee ID | Date of visit | Discipline | Previous occurrence |
1 | 9/1/2021 | RN | |
1 | 9/6/2021 | CNA | |
1 | 9/10/2021 | RN | 9/1/2021 |
1 | 9/25/2021 | RN | 9/10/2021 |
2 | 9/5/2021 | RN | |
2 | 9/10/2021 | RN | 9/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
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
Hi, nope. None of the suggestions helped get what I was looking for.
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
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!
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]
)
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! |
Can't use MAXX in Direct Query either
@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.
This is the error message i am receiving. I am unable to change from DirectQuery.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
117 | |
104 | |
77 | |
73 | |
52 |
User | Count |
---|---|
145 | |
109 | |
109 | |
90 | |
64 |