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

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.

Reply
ruban
Frequent Visitor

Get next visit on a customer

Hi,

I have a table which contains customer id and visit date . I want to create a new column which holds the next visit  date. Example. If a customer has 3 visits. I wish to see the second visit date on the new column of the same row of first visit and so on.

I feel it could be done by creating an index column but I am not completely sure on how to make do it. Attaching an image to explain my requirement.

next visit.JPG 

 

Thanks,

Ruban

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @ruban 

 

The same solution can be achedived by creating a calculated column as well.

 

Next Visist Date = CALCULATE(MIN('Customer Visit Table'[Visit_Date]),
                                FILTER('Next Visit Date','Customer Visit Table'[CID]= EARLIER('Customer Visit Table'[CID]) 
                                 && 'Customer Visit Table'[Visit_Date] >EARLIER('Customer Visit Table'[Visit_Date])))

Please note that this  will not respond to slicer selection as its calculated column.

 

Thanks

Raj

 

Did i answer your Question? Please mark my answer as Solution.

Proud to be a Datanaut!

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @ruban 

 

Please create the new calculated table using this DAX:

New Next Visit Table = 
VAR vSelfjoin= FILTER( 
                     GENERATE('Customer Visit Table',
                               SELECTCOLUMNS('Customer Visit Table',
                                 "xCID" , 'Customer Visit Table'[CID],
                                 "xVisit_Date", 'Customer Visit Table'[Visit_Date])
                        ) 
                        ,'Customer Visit Table'[CID]=[xCID] &&
                         [xVisit_Date]>'Customer Visit Table'[Visit_Date]
)    
VAR vLastVisitDate = GROUPBY(vSelfjoin,
                              'Customer Visit Table'[CID],
                              'Customer Visit Table'[Visit_Date],
                              "Next Visit Date", MINX(CURRENTGROUP(),[xVisit_Date])
                              )  
RETURN NATURALLEFTOUTERJOIN('Customer Visit Table',vLastVisitDate)
                          

Then pull the columns from this new table:

 

Next Visit Date.PNG

Thanks

Raj

 

Did i answer your Question? Please mark my answer as Solution.

Proud to be a Datanaut!

Anonymous
Not applicable

Hi @ruban 

 

The same solution can be achedived by creating a calculated column as well.

 

Next Visist Date = CALCULATE(MIN('Customer Visit Table'[Visit_Date]),
                                FILTER('Next Visit Date','Customer Visit Table'[CID]= EARLIER('Customer Visit Table'[CID]) 
                                 && 'Customer Visit Table'[Visit_Date] >EARLIER('Customer Visit Table'[Visit_Date])))

Please note that this  will not respond to slicer selection as its calculated column.

 

Thanks

Raj

 

Did i answer your Question? Please mark my answer as Solution.

Proud to be a Datanaut!

Hi Raj,

Could you share the table image when you use calculated column?

 

Regards,

Ruban 

Anonymous
Not applicable

Its same as above image. Thanks Raj

Hi Raj,

 

When I use your DAX for the calculated column , I get the previous visit date instead of next visit date . Could you hep me solve it?

next visit 2.JPG

Anonymous
Not applicable

oh, got it. I tested the code for past date as well and paasted that code here. Updated my above post, try it now.

 

Thanks

Raj

 thanks Raj. It worked perfectly.

 

Regards,

Ruban 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.