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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
czuniga
Helper III
Helper III

Comparing GroupedBy Dates

I have a list of customers and the dates of their appointments like so:

 

Customer IDAptDate
1111/1/2019
1111/5/2019
2222/3/2020
4442/4/2020
5552/5/2020
5552/6/2020
5552/7/2020
8882/8/2020
9992/9/2020
9992/10/2020
9992/11/2020

 

I'm trying to figure out how to keep track of the success rate of scheduling customers next appointment when they visit.  Successful Dataset would look like this (1 = NextAptScheduled): 

 

Customer IDAptDate (Past & Future)NextAptScheduled
1111/1/20191
1115/1/20210
2222/3/20200
4442/4/20200
5552/5/20201
5552/6/20201
5552/7/20200
8882/8/20200
9992/9/20201
9992/10/20201
9992/11/20220

 

I'm thinking it makes sense to group the customers by their ID's with the dates of their purchases, but am having a hard time figuring if I should do that with a groupby, summarize,  or summarizecolumns, and how to work with the dates in their respective groups to achieve the goal from there. 

 

Any help would be greatly appreciated. Thank you! 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=1*(not(CALCULATE(MAX(Data[AptDate (Past & Future)]),FILTER(Data,Data[Customer ID]=EARLIER(Data[Customer ID])))=Data[AptDate (Past & Future)]))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

=1*(not(CALCULATE(MAX(Data[AptDate (Past & Future)]),FILTER(Data,Data[Customer ID]=EARLIER(Data[Customer ID])))=Data[AptDate (Past & Future)]))

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
mahoneypat
Employee
Employee

You can use this expression for a new Column on your Appointments table (replace with your actual table name).  I added a comment too in case you need the measure version in a table visual with your customer ID and Date columns.

 

NextApptScheduled =
VAR vThisDate = Appointments[AptDate]  //use MIN(Appointments[AptDate]) if a measure is needed instead
RETURN
    IF (
        ISBLANK (
            CALCULATE (
                COUNTROWS ( Appointments ),
                ALLEXCEPT (
                    Appointments,
                    Appointments[Customer ID]
                ),
                Appointments[AptDate] > vThisDate
            )
        ),
        0,
        1
    )

 

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


PhilipTreacy
Super User
Super User

Hi @czuniga 

Please supply some sample data and your expected result so we can see what we're working with.

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Thanks for the suggestion. Done! 

amitchandak
Super User
Super User

@czuniga , expected output is not clear . But these columns can help

 

rank Column for dates = rankx(filter(Table, [Customer] = earlier([customer]) ), [Date],,asc)


last purcahse date date = maxx(filter(Table, [Customer] = earlier([customer]) && [Date] = earlier([Date])),[Date])

Tried again to explain what I'm trying to accomplish as I wasn't able to get what you suggested work. Appreciate the input though! 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.