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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
pconnon
Frequent Visitor

Calculate FIXED months between two dates

I'm trying to calculate a count of months between date slicer dates to used it as a denomitar in order to calculate an average based on all periods for all customers. 

 

The idea is to calculate the average of sales between 2 dates for each customer, but globally and not only considering the months I got a sale to a customer. In example, in a 24 months period what's the sales average fot customer X who a only sale him on march and june 2018?

 

any ideas?

1 ACCEPTED SOLUTION

I tried this solution, but the problem was that when I use the result on a table with all my customers this value was reevaluated for each customer with only the dates on which the sales where made and I needed a fixed value.

 

What I did was to create a new table CALENDAR

 

Calendar = CALENDAR( DATE(2015;01;01) ; DATE(2020;01;01))

 

and use these values on the slicer instead of the sales dates. With these changes I was able to calculate a sales frequency for each customer on a fixed period.

 

thanks! 

View solution in original post

3 REPLIES 3
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @@pconno,



As Greg_Deckler suggested, you could calculate the a count of months between date slicer dates use DATEDIFF of the MAX and MIN of your slicer like below.

 

calculate the month between date slicer.PNG

If you have solved your problem, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

 

If you still need help, please share some data sample and your desired output so that we could help further on it.

 

Best  Regards,

Cherry

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

I tried this solution, but the problem was that when I use the result on a table with all my customers this value was reevaluated for each customer with only the dates on which the sales where made and I needed a fixed value.

 

What I did was to create a new table CALENDAR

 

Calendar = CALENDAR( DATE(2015;01;01) ; DATE(2020;01;01))

 

and use these values on the slicer instead of the sales dates. With these changes I was able to calculate a sales frequency for each customer on a fixed period.

 

thanks! 

Greg_Deckler
Super User
Super User

Seems like you could use DATEDIFF of the MAX and MIN of your slicer.



Follow on LinkedIn
@ 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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

May 2025 Monthly Update

Fabric Community Update - May 2025

Find out what's new and trending in the Fabric community.