March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
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!
Solved! Go to 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())
)
Best regards,
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
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.
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)))
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))
Best regards,
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])
Sorry, it did not help. 😞
https://drive.google.com/open?id=1odHd5gv2RkBBnvTFukZFBAm6T9uyq3Kx
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
)
)
Best regards,
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?
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())
)
Best regards,
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.
Many many thanks!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
123 | |
86 | |
73 | |
58 | |
52 |
User | Count |
---|---|
196 | |
125 | |
107 | |
68 | |
65 |