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

Count a number of months after registration

Greetings,

 

I have a task that seems simple, but I can't address it.

 

There are 2 linked tables

1. Dates (with columns Date, Month, Year, Month+Year)

2. Clients (Client ID and Registration date)

 

I need to calculate the number of months after registration for each client.

 

After that, I need to get a measure that gives me an average of the above calculation per month.

 

Any help is highly appreciated!

 

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

We can try to use the following measure to meet your requirement:

 

Measure = 
VAR d =
    MIN ( 'Dates'[Date] )
RETURN
    AVERAGEX (
        FILTERS('Clients'[Client ID]),
        var i = [Client ID] 
        var r =
        DATEDIFF (
            CALCULATE (
                MIN ( 'Clients'[Registration date] ),
                FILTER (
                    ALLSELECTED(  'Clients' ),
                    'Clients'[Client ID] = i
                )
            ),
            d,
            MONTH
        )
        return IF(r>0,r,BLANK())
    )
    

 

2.jpg


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

12 REPLIES 12
amitchandak
Super User
Super User

In case you want a column

new column in client = datediff(client[date],today(),MONTH)

 

In case you want measure dynamic to change based on selection
new Measure = calculate(averagex(summarize(client,client[Id], "_reg_date",min(client[date]),"_max_td",max(date[date])),datediff(_reg_date,_max_td,MONTH)))

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

Hi @amitchandak ,

 

Thank you for your answer!

 

I applied this measure formula and it partially works.

Unfortunately, it shows "0" in a month when registration was done and Blank in other cells.

External link to the picture 

 

Could you advise how to fix it?

 

Thanks,

Oleg

Missed [ and ]

new Measure = calculate(averagex(summarize(client,client[Id], "_reg_date",min(client[date]),"_max_td",max(date[date])),datediff([_reg_date],[_max_td],MONTH)))
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

Hi @amitchandak,

 

Sorry, I don't fully understand what was missed.

I checked your last formula with a previous and the one I use, all of them are the same.

Could you specify in details what I need to change?

 

Thank you,

Oleg

Hi @Anonymous ,

 

We can try to use the following measures to meet your requirement:

 

Measure = AVERAGEX('Clients',DATEDIFF(CALCULATE(MIN('Clients'[Registration date])),CALCULATE(MIN('Dates'[Date])),MONTH))

 

1.jpg2.jpg


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-lid-msft ,

 

Thank you for your suggestion!

I don't know why I got "0" again.

Those "0" are on the month when registration was done, so it identifies it correctly.

There are no filters, all columns data types are correct.

 

Here is a screenshot(I don't know why I can't add an image here):

https://drive.google.com/open?id=1drWIZ-c-ZBiyQeIUdVvMbDkryawC0ND0

In averagex try the first parameter as averagex(values(client[clientID])

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
Anonymous
Not applicable

Hi @Anonymous ,

 

We can try to use the following measure to met your requirement if two tables have 1:M relationship:

 

Measure = 
VAR d =
    MIN ( 'Dates'[Date] )
RETURN
    AVERAGEX (
        FILTERS('Clients'[Client ID]),
        var i = [Client ID] return
        DATEDIFF (
            CALCULATE (
                MIN ( 'Clients'[Registration date] ),
                FILTER (
                    ALLSELECTED(  'Clients' ),
                    'Clients'[Client ID] = i
                )
            ),
            d,
            MONTH
        )
    )
    

 

2.jpg3+.jpg


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-lid-msft ,

 

Yes, this measure works in the same way as shown in your image, thank you!

 

The only issue that is left that I need to avoid negative numbers in order to show a true average per month.

Filter by measure value doesn't help.

Could you help me with this?

 

Here is my picture

 

Hi @Anonymous ,

 

We can try to use the following measure to meet your requirement:

 

Measure = 
VAR d =
    MIN ( 'Dates'[Date] )
RETURN
    AVERAGEX (
        FILTERS('Clients'[Client ID]),
        var i = [Client ID] 
        var r =
        DATEDIFF (
            CALCULATE (
                MIN ( 'Clients'[Registration date] ),
                FILTER (
                    ALLSELECTED(  'Clients' ),
                    'Clients'[Client ID] = i
                )
            ),
            d,
            MONTH
        )
        return IF(r>0,r,BLANK())
    )
    

 

2.jpg


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

Hi @v-lid-msft,

 

Great! It is perfect.

The only thing I changed is

 return IF(r>=0,r,BLANK())

Otherwise, the first month is lost.

A picture of result

 

Many many thanks!

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.