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
JohnM1985
Regular Visitor

Count of active items by date

Hi,

 

I have a table of accounts, which includes the account number, status (A=Active, C=Closed), account opening date and closing date (blank if still open).

 

Both of the date columns have an inactive relationship to a calendar[Date] field - inactive due to a previous relationship which would introduce ambiguity between other tables.

 

 I am trying to create a simple visualisation which would result in showing the amount of active accounts at a given date, with an additional visualisation showing the amount opened and closed in the period - preferably monthly.

A simplified version of my table is shown below:

 

account_number open_date close_date status
1 01/12/2021 01/01/2023 C
2 01/12/2021   A
3 01/03/2022   A
4 01/03/2022 01/03/2023 C
5 01/06/2022   A
6 01/12/2022   A
7 01/03/2023 01/03/2023 C
8 01/06/2023 01/09/2023 C
9 01/09/2023   A
10 01/12/2023   A


If displayed numerically I would expect the results to look similar to below:

Date Running count of open accounts Opened Closed
01/12/2021 2 2 0
01/03/2022 4 2 0
01/06/2022 5 1 0
01/09/2022 5 0 0
01/12/2022 6 1 0
01/03/2023 4 1 3
01/06/2023 5 1 0
01/09/2023 5 1 1
01/12/2023 6 1 0


I've tried a variety of measures with no success, so would appreciate some help.

Thanks in advance!

1 ACCEPTED SOLUTION
JohnM1985
Regular Visitor

Hi @Abhilash_P , thanks so much for your quick response.

I had to make a couple of tweaks as the relationships had to stay inactive due to other connections, but all resolved now.  Thanks so much for your help!

 

View solution in original post

2 REPLIES 2
JohnM1985
Regular Visitor

Hi @Abhilash_P , thanks so much for your quick response.

I had to make a couple of tweaks as the relationships had to stay inactive due to other connections, but all resolved now.  Thanks so much for your help!

 

Abhilash_P
Helper II
Helper II

Hi @JohnM1985 ,

 

You can create calendar table using below dax 

Abhilash_P_0-1686099264883.png



- Create Active relationship between calendar table date to open_date
- Create Incative relationship between calendar table date to close_date userrelationship dax to get count of closed accounts.

Abhilash_P_1-1686099354091.png      

Abhilash_P_2-1686099399214.png

 

Create below measures

1. OPEN = CALCULATE(COUNT('Table'[open_date]),'Table'[status] = "A")
 
 
2.Closed=CALCULATE(COUNT('Table'[close_date]),USERELATIONSHIP('Table'[close_date],'Calendar'[Date]),'Table'[status] = "C")
 
3. Count of account numbers = COUNT('Table'[account_number])
 
 
4. Running count of open accounts =
VAR MaxD = MAX('Table'[open_date])
return
CALCULATE([Count of account numbers],'Calendar'[Date] <= MaxD,ALL('Calendar'[Date]))
 
 
below is your output.date in below  table should be selected from calendar table
Abhilash_P_3-1686099695158.png

 

 


Regards
 

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.