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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

How to get the aging in each month

I want to get the aging of the items in each month from opened date to closed date.

So for the table below, what would be the age of the items below in April, then May, June and so forth. The aging will stop once the fill date has come. If no fill date, then today will be used.

 

Opened DateClosed DateAprilMayJuneJulyAugust
5/1/20238/16/2023     
4/1/2023      


Hope this makes sense. Thanks in advance!

1 ACCEPTED SOLUTION

I assume you have a Date table. Here is the measure:

age =
VAR monthStart = MIN ( 'Date'[Date] )
VAR monthEnd = MAX ( 'Date'[Date] )
VAR opened = SELECTEDVALUE ( 'Table'[Opened Date] )
VAR closed = COALESCE ( SELECTEDVALUE ( 'Table'[Closed Date] ), TODAY () )
VAR days = DATEDIFF ( opened, monthEnd, DAY ) + 1
RETURN
    IF ( TODAY () > monthEnd && monthStart >= opened && monthEnd <= closed, days )

ERD_0-1695194665618.png

 

 

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

8 REPLIES 8
ERD
Super User
Super User

Hi @Anonymous , should the age be in days or months? As far as I understand you have a matrix with months as columns.

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Anonymous
Not applicable

Hi! The age should be in days. For the months in columns, I want to know the age if that month is finished.

I assume you have a Date table. Here is the measure:

age =
VAR monthStart = MIN ( 'Date'[Date] )
VAR monthEnd = MAX ( 'Date'[Date] )
VAR opened = SELECTEDVALUE ( 'Table'[Opened Date] )
VAR closed = COALESCE ( SELECTEDVALUE ( 'Table'[Closed Date] ), TODAY () )
VAR days = DATEDIFF ( opened, monthEnd, DAY ) + 1
RETURN
    IF ( TODAY () > monthEnd && monthStart >= opened && monthEnd <= closed, days )

ERD_0-1695194665618.png

 

 

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Anonymous
Not applicable

Thank you so much for your help, Mate! One last question, what if I want to get the age up to the current day or up to the closed date? for example in the row 2, the closed date is 8/16, right? I want to get the age on the August column but up to the August 16 only.

age =
VAR monthStart =
    MIN ( 'Date'[Date] )
VAR monthEnd =
    MAX ( 'Date'[Date] )
VAR opened =
    SELECTEDVALUE ( 'Table'[Opened Date] )
VAR closed =
    COALESCE ( SELECTEDVALUE ( 'Table'[Closed Date] ), TODAY () )
VAR days =
    DATEDIFF ( opened, monthEnd, DAY ) + 1
VAR endDay =
    IF ( monthEnd <= closed, monthEnd, closed )
VAR days_last =
    DATEDIFF ( opened, endDay, DAY ) + 1
RETURN
    IF ( TODAY () > monthEnd && monthStart >= opened, days_last )

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Anonymous
Not applicable

Thanks for this. My problem with this is that if the monthEnd is greater than today and the monthStart < opened, the data is skewed and I tried creating a solution but to no avail. 😞

Anonymous
Not applicable

This is perfecly working! I have another question, would it be possible to count the number of items whose age is 90+? For example, in the month of June, there is 1 item whose age is 91 so that should count as 1 for the month of June only.

Hi. Yes.

age 90+ = 
    VAR t =
        FILTER (
            ADDCOLUMNS (
                GENERATE (
                    VALUES ( 'Date'[Month-Year] ),
                    SUMMARIZE ( 'Table', 'Table'[Opened Date], 'Table'[Closed Date] )
                ),
                "@age", [age]
            ),
            [@age] >= 90
        )
    RETURN
        COUNTROWS ( t )

ERD_0-1695279640330.png

 

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

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.