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
nsiu85
Frequent Visitor

Calculate total count of clients at the end of each month, quarter, and fiscal year

Hi,

 

I am quite new to Power BI and using DAX. How do I go about calculating the total number of client at the end of each month, quarter and fiscal year. The criteria to give a total number of client at the end of each month would require:

 

  • new clients within the month, and
  • client that already existed but still remain active at the clinic, and
  • client exiting within the month

Have include a very small sample data set as an example and the result of it

Client IDStart DateCloseExit Date
10927/11/2019Y3/12/2020
10727/11/2019N 
10827/11/2019Y3/02/2021
1139/01/2020Y11/02/2021
11215/01/2020Y18/07/2020
11115/02/2020N 
11415/03/2020N 
11515/05/2020Y8/10/2020
11716/05/2020Y20/12/2020
11616/08/2020Y20/12/2020
1236/10/2020Y6/12/2020
1226/10/2020N 
1216/12/2020Y28/01/2021
12221/03/2021N 

 

In Power BI should have something like this:

2019
MonthNewExistingExit
Nov3  
Dec 3 

 

2020
MonthNewExistingExit
Jan23 
Feb15 
Mar16 
Apr 7 
May27 
Jun 9 
Jul 91
Aug 9 
Sep 9 
Oct291
Nov 10 
Dec1105

 

2021
MonthNewExistingExit
Jan 61
Feb 51
Mar14 
Apr 5 

 

Any advice or help would be great.

6 REPLIES 6
nsiu85
Frequent Visitor

Hi @tamerj1 

I had a go in using the DAX functions you provided and make the necessary changes to reflect what is on my table of data and columns. However, when I select existing and exit measure no data is shown. It is presented blank

Hi @nsiu85 

please provide details on these changes and advise what are the differences in your model. Do you have relationships with the date table?

Yes I have relationships link to the date table. I have Date with Episode Start Date (aka start date) linked as one to many relationship.

nsiu85_1-1680496200557.png

 

Here is the coding I used from what you have provided and replaced start date with Episode Start Date and exit date with date closed. Not sure what is happening here. 

 

nsiu85_0-1680496137771.png

 

nsiu85_2-1680496287020.png

 

nsiu85_3-1680496558794.png

 

 

@nsiu85 
You can just delete or deactivate he relationship. If for any reason you wish to keep it, you can follow the attached updated sample file

1.png

New = 
CALCULATE ( 
    COUNTROWS ( 'Table' ),
    TREATAS ( VALUES ( 'Date'[Date] ), 'Table'[Start Date] ),
    ALL ( 'Date' )
)
Existing = 
VAR MaxDate = MAX ( 'Date'[Date] )
VAR MinDate = MIN ( 'Date'[Date] )
RETURN
    COUNTROWS ( 
        FILTER ( 
            CALCULATETABLE ( 'Table', ALL ( 'Date' ) ),
            'Table'[Start Date] <= MinDate
                && COALESCE ( 'Table'[Exit Date], TODAY ( ) ) >= MaxDate
        )
    )
Exit = 
IF ( 
    NOT ISEMPTY ( 'Date' ),
    CALCULATE ( 
        COUNTROWS ( 'Table' ),
        TREATAS ( VALUES ( 'Date'[Date] ), 'Table'[Exit Date] ),
        ALL ( 'Date' )
    )
)
nsiu85
Frequent Visitor

Thank you @tamerj1 let me have a play with the big data set I have and see if I get what I need from the report.

tamerj1
Super User
Super User

Hi @nsiu85 
Please refer to attached sample file with the solution

1.png2.png

New = 
CALCULATE ( 
    COUNTROWS ( 'Table' ),
    TREATAS ( VALUES ( 'Date'[Date] ), 'Table'[Start Date] ) 
)
Exit = 
CALCULATE ( 
    COUNTROWS ( 'Table' ),
    TREATAS ( VALUES ( 'Date'[Date] ), 'Table'[Exit Date] ) 
)
Existing = 
VAR MaxDate = MAX ( 'Date'[Date] )
VAR MinDate = MIN ( 'Date'[Date] )
RETURN
    COUNTROWS ( 
        FILTER ( 
            'Table',
            'Table'[Start Date] <= MinDate
                && COALESCE ( 'Table'[Exit Date], TODAY ( ) ) >= MaxDate
        )
    )

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.

Top Solution Authors