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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Elisa112
Helper V
Helper V

Find the number of working days between clients appointments of different types

Hello, I am working on a KPI to report on the number of working days between clients booked appointments of different types, here is an example of the data:

 

Elisa112_0-1706109225059.png

As time goes on each client will have several appointments however I need to report on the most 3 or 4 recent appointments, regardless of whether they are attended or not, and regardless of type, so the output should be something like this:

 

Elisa112_1-1706109566442.png

Im not sure what the most effective solution would be i.e indexing the data or create a summarized table? Either of which I could do with an example

thank you in advance

 

1 ACCEPTED SOLUTION

Hi @Anonymous 

Thank you for this, I think this is what I am looking for, all was working well except the summary table is showing this output

 

Elisa112_0-1706199176526.png

As you can see the date for 2nd meeting is the same for all users. Which is strange as the ranking function is working fine for 1st and 3rd meetings. I cannot see any difference in the DAX so not sure what is happening.

Also I will always need to find the most recent 3 dates (which could be 9,10, 11 for one user and 1,2,3 for another.

Any further help greatly appreciated, I believe this will work with a few tweeks, 

Thanks again

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Elisa112 ,

Here some steps that I want to share, you can check them if they suitable for your requirement.

Here is my test data:

vheqmsft_1-1706162668888.png

1.Create a custom column Group the tables by UserID and then sort them by Date within the group.

Ranking =
RANKX (
    FILTER ( 'Table', 'Table'[UserID] = EARLIER ( 'Table'[UserID] ) ),
    'Table'[Date],
    ,
    ASC,
    DENSE
)

vheqmsft_2-1706162832355.png

2.Create a new table and get the time of the first, second and third meeting.

SummaryTable = 
SUMMARIZECOLUMNS(
    'Table'[UserID],
    "1st Meeting",CALCULATE(
        MIN('Table'[Date]),
        FILTER(
            'Table',
            'Table'[UserID] = SELECTEDVALUE('Table'[UserID])&&'Table'[Ranking] =1)
    ),
    "2nd Meeting",CALCULATE(
        MIN('Table'[Date]),
        FILTER(
            'Table',
            'Table'[UserID] = SELECTEDVALUE('Table'[UserID])&&'Table'[Ranking] =2)
    ),
    "3nd Meeting",CALCULATE(
        MIN('Table'[Date]),
        FILTER(
            'Table',
            'Table'[UserID] = SELECTEDVALUE('Table'[UserID])&&'Table'[Ranking] =3)
    )
)

3.Create  new calculation columns to calculate the difference in working days between dates.

WorkingDayDiff =
VAR StartDate = SummaryTable[1st Meeting]
VAR EndDate = SummaryTable[2nd Meeting]
VAR WorkingDays =
    COUNTROWS (
        FILTER ( CALENDAR ( StartDate, EndDate ), WEEKDAY ( [Date], 2 ) < 6 )
    )
RETURN
    WorkingDays
WorkingDay Diff = 
VAR StartDate = SummaryTable[2nd Meeting]
VAR EndDate = IF(
    SummaryTable[3nd Meeting] = BLANK(),
    DATE(2023,12,31),
    SummaryTable[3nd Meeting]
)
VAR WorkingDays = 
    COUNTROWS(
        FILTER(
            CALENDAR(StartDate, EndDate),
            WEEKDAY([Date], 2) < 6
        )
    )
RETURN
    WorkingDays

4.Because the parameters in the calender function can not be empty, so it gives a fixed value, and finally after the creation of a column filter can be used to filter abnormal data

vheqmsft_3-1706163547554.png

5.Final output

vheqmsft_4-1706163573134.png

 

Best regards

Albert He

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly



 

Hi @Anonymous 

Thank you for this, I think this is what I am looking for, all was working well except the summary table is showing this output

 

Elisa112_0-1706199176526.png

As you can see the date for 2nd meeting is the same for all users. Which is strange as the ranking function is working fine for 1st and 3rd meetings. I cannot see any difference in the DAX so not sure what is happening.

Also I will always need to find the most recent 3 dates (which could be 9,10, 11 for one user and 1,2,3 for another.

Any further help greatly appreciated, I believe this will work with a few tweeks, 

Thanks again

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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