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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
jmarciogsousa
Frequent Visitor

Calculate Number of Units Per Month Based on Start and End Dates

Hi,

Use case: Count the number of cars available per month based on a start and end dates.
Model: The model is simple one calendar and another fact table without relationship.

Dax Formulas: I have achive this with 2 formulas, one is correct but with bad performance another total is not correct for totals but the performance is good:

jmarciogsousa_1-1726310406726.png

Pbix File: File with Example 
Could you support me to achive the correct value with good performance.


 

2 ACCEPTED SOLUTIONS
tharunkumarRTK
Super User
Super User

@jmarciogsousa 

You can try this formula:

_Cars_PerMonthAndDay = 
Var __Result =  SUMX(
                    'Calendar', 
                    Var __Date = 'Calendar'[Date]
                   return  COUNTROWS(
                        FILTER(
                            Cars, 
                            Cars[ValidFrom] <= __Date &&
                            Cars[ValidUntil] >= __Date
                        )
                   )
)
RETURN __Result  

 

In my observation, the results are accurate and it is performing better than your version. 

Need a Power BI Consultation? Hire me on Upwork

 

 

 

Connect on LinkedIn

 

 

 








Did I answer your question? Mark my post as a solution!
If I helped you, click on the Thumbs Up to give Kudos.

Proud to be a Super User!


PBI_SuperUser_Rank@2x.png

View solution in original post

ThxAlot
Super User
Super User

 

_Cars_PerMonthAndDay = 
SUMX(
    Cars,
    VAR __from = Cars[ValidFrom]
    VAR __until = Cars[ValidUntil]
    RETURN
        CALCULATE(
            COUNTROWS( 'Calendar' ),
            'Calendar'[Date] >= __from,
            'Calendar'[Date] <= __until
        )
)

 



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



View solution in original post

2 REPLIES 2
ThxAlot
Super User
Super User

 

_Cars_PerMonthAndDay = 
SUMX(
    Cars,
    VAR __from = Cars[ValidFrom]
    VAR __until = Cars[ValidUntil]
    RETURN
        CALCULATE(
            COUNTROWS( 'Calendar' ),
            'Calendar'[Date] >= __from,
            'Calendar'[Date] <= __until
        )
)

 



Expertise = List.Accumulate(


        {Days as from Today},


        {Skills and Knowledge},


        (Current, Everyday) => Current & Day.LearnAndPractise(Everyday)


)



tharunkumarRTK
Super User
Super User

@jmarciogsousa 

You can try this formula:

_Cars_PerMonthAndDay = 
Var __Result =  SUMX(
                    'Calendar', 
                    Var __Date = 'Calendar'[Date]
                   return  COUNTROWS(
                        FILTER(
                            Cars, 
                            Cars[ValidFrom] <= __Date &&
                            Cars[ValidUntil] >= __Date
                        )
                   )
)
RETURN __Result  

 

In my observation, the results are accurate and it is performing better than your version. 

Need a Power BI Consultation? Hire me on Upwork

 

 

 

Connect on LinkedIn

 

 

 








Did I answer your question? Mark my post as a solution!
If I helped you, click on the Thumbs Up to give Kudos.

Proud to be a Super User!


PBI_SuperUser_Rank@2x.png

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

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.

June 2025 community update carousel

Fabric Community Update - June 2025

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