cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

Count days between first two dates in same column for same user

Hi ! Been struggling with this and I can't get this to work How can I achieve the last column ? 


idusertrx datedates between 1st and 2nd trx date
111.1.2020 
2121.1.2020 
3122.2.202032
4473.3.2020 
5473.3.20200
624.4.2020 
7125.5.2020 

As a calculated column I'm using functions like EARLIER() but with no success

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Champion
Community Champion

Re: Count days between first two dates in same column for same user

@Yggdrasill 

Add this as a column to your table:

DaysDiff = 
VAR __USER = [user] RETURN
VAR __MIN = 
MINX(
    CALCULATETABLE(
        TOPN(2, Table1, Table1[trx date], ASC ),
        ALLEXCEPT(Table1,Table1[user])),
     Table1[trx date]
)
VAR __MAX = 
MAXX(
    CALCULATETABLE(
        TOPN(2, Table1, Table1[trx date], ASC ),
        ALLEXCEPT(Table1,Table1[user])),
     Table1[trx date]
)
RETURN
IF(
    [trx date] = __MAX, DATEDIFF( __MIN, __MAX, DAY)
)

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

View solution in original post

2 REPLIES 2
Highlighted
Community Champion
Community Champion

Re: Count days between first two dates in same column for same user

@Yggdrasill 

Add this as a column to your table:

DaysDiff = 
VAR __USER = [user] RETURN
VAR __MIN = 
MINX(
    CALCULATETABLE(
        TOPN(2, Table1, Table1[trx date], ASC ),
        ALLEXCEPT(Table1,Table1[user])),
     Table1[trx date]
)
VAR __MAX = 
MAXX(
    CALCULATETABLE(
        TOPN(2, Table1, Table1[trx date], ASC ),
        ALLEXCEPT(Table1,Table1[user])),
     Table1[trx date]
)
RETURN
IF(
    [trx date] = __MAX, DATEDIFF( __MIN, __MAX, DAY)
)

________________________

If my answer was helpful, please consider Accept it as the solution to help the other members find it

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube  LinkedIn

View solution in original post

Highlighted
Helper V
Helper V

Re: Count days between first two dates in same column for same user

You absolute beauty ! Thank you !

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Upcoming Events

Experience what’s next for Power BI

See the latest Power BI innovations, updates, and demos from the Microsoft Business Applications Launch Event.

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Top Solution Authors
Top Kudoed Authors