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
billuran
Helper I
Helper I

Average Age of Accounts by Month

Hello,  For simplicity, I have a table

AcctID Opened_DateClosed _Date

1

1/8/20202/5/2020
21/9/20201/31/2020
32/1/20203/15/2020

 

I need to caluclate the age of the account at the beginning of every month of 2020

Result I need for my 100,000s records

 

DateAvg Age at Date (Logic for bi community help)
1/1/2020       0(None are Open then)
2/1/2020       23.5(Avg of 1 and 2 because both are open at 2/1)
3/1/2020       29 (BC 1 and 2 are closed and Account 3 is open and 29 days old)
4/1/2020       0(bc account 3 has closed by 4/1)

 

1 ACCEPTED SOLUTION

Hi @billuran ,

 

We have a little confused about your issue, what the total avg age?

Is it the Total day of the current month divided by the ID of the current month?

For example, the 2020/2/1 has two ID, the total day is 23 + 24 = 47. So the result is 47 / 2 = 23.5

If yes, you can refer the following steps.

 

1. Create a calculate column named Month date.

 

Month Date = CALCULATE(MIN('Date table'[Date]),FILTER('Date table','Date table'[Date]>'Table'[Opened_Date]))

 

av1.jpg

 

2. Then create the difference days column.

 

difference = DATEDIFF('Table'[Opened_Date],'Table'[Month Date],DAY)

 

av2.jpg

 

3. Then we can create the Total measure and result measure.

 

Total = SUM('Table'[difference])+0

 

Measure = 
var _amount = DISTINCTCOUNT('Table'[AcctID])
return
DIVIDE([Total],_amount)

 

av3.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

View solution in original post

6 REPLIES 6
v-zhenbw-msft
Community Support
Community Support

Hi @billuran ,

 

We can create a calculate column and a relationship, then create a measure to meet your requirement.

 

1. Create a calculate column that gets the min month date.

 

Month Date = CALCULATE(MIN('Date table'[Date]),FILTER('Date table','Date table'[Date]>'Table'[ Opened_Date]))

 

Av1.jpg

 

2. We can create a one-to-many relationship between table and Date table.

 

Av2.jpg

 

3. Then we can create a measure and the result like this,

 

Measure = AVERAGEX('Table',DATEDIFF('Table'[ Opened_Date],'Table'[Month Date],DAY))+0

 

Av3.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

The formula seems to only show the avg age between Month Date, I woudl like the total avg age from Opened to the Month Date

Hi @billuran ,

 

We have a little confused about your issue, what the total avg age?

Is it the Total day of the current month divided by the ID of the current month?

For example, the 2020/2/1 has two ID, the total day is 23 + 24 = 47. So the result is 47 / 2 = 23.5

If yes, you can refer the following steps.

 

1. Create a calculate column named Month date.

 

Month Date = CALCULATE(MIN('Date table'[Date]),FILTER('Date table','Date table'[Date]>'Table'[Opened_Date]))

 

av1.jpg

 

2. Then create the difference days column.

 

difference = DATEDIFF('Table'[Opened_Date],'Table'[Month Date],DAY)

 

av2.jpg

 

3. Then we can create the Total measure and result measure.

 

Total = SUM('Table'[difference])+0

 

Measure = 
var _amount = DISTINCTCOUNT('Table'[AcctID])
return
DIVIDE([Total],_amount)

 

av3.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

Hi @billuran ,

 

How about the result after you follow the suggestions mentioned in my original post?

Could you please provide more details or expected result about it If it doesn't meet your requirement?

If you've fixed the issue on your own please kindly share your solution. If the above posts help, please kindly mark it as a solution to help others find it more quickly.

 

Best regards,

 

Community Support Team _ zhenbw

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

Greg_Deckler
Super User
Super User

@billuran - Perhaps:

Measure =
  AVERAGEX(FILTER('Table',[Opened_Date]>MAX([Date])),([Closed Date] - [Opened Date])*1.)

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.