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
bhorvati
Frequent Visitor

Divide By Number of Months YTD

I want to divide by total inventory by the number of months YTD.   The count function gives me all of the months in my calendar table.  How do I filter it just for the current year that will be a filtered selection?    Example:  So if my data is through May, it will divide by 5. 

 

 

Averge Inventory = DIVIDE(CALCULATE([Inventory], DATESYTD(d_DateTable[Date])), COUNT(d_DateTable[Month]))

 

 

I researched forums and tried a dozen different fomulas.  Sorry, I am beginner.  

1 ACCEPTED SOLUTION

Hi @bhorvati,

 

I'm assuming your calendar table is related with your inventory table.

 

Create a month column on your inventory table then change your measure to:

 

Average Inventory_distinct_Count =
DIVIDE (
    CALCULATE ( [Inventory]; DATESYTD ( d_DateTable[Date] ) );
    MAX('Table'[Month_])
)

When you divide the number by count you will get every single row so in January you will get 31 days, you need to get the distinct number of that month in this case I have it by the MAX formula of the inventory table:

 

total.png

 

 

Regards,

MFelix

 

 

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

7 REPLIES 7
MFelix
Super User
Super User

Hi @bhorvati,

Instead of COUNT use DISTINCTCOUNT should work as you need.

Regards,
MFelix

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



MattAllington
Community Champion
Community Champion

Try this

 

Months YTD =  totalytd(countrows(values(d_DateTable[Month])),d_DateTable[Date])



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Hi @MattAllington Solution provided, returned a month count of 12 when my data is through May, thus i need the count to be 5.   The only page filter I have on is year.  

 

By the way, I've been watching your videos on YouTube.  Thanks sharing all the content and advice.  

Hi @bhorvati,

 

I'm assuming your calendar table is related with your inventory table.

 

Create a month column on your inventory table then change your measure to:

 

Average Inventory_distinct_Count =
DIVIDE (
    CALCULATE ( [Inventory]; DATESYTD ( d_DateTable[Date] ) );
    MAX('Table'[Month_])
)

When you divide the number by count you will get every single row so in January you will get 31 days, you need to get the distinct number of that month in this case I have it by the MAX formula of the inventory table:

 

total.png

 

 

Regards,

MFelix

 

 

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



@MFelix  Thank your for your reply, but can you look at my formula and see if you can see what I am doing wrong.   My formula is still picking up the MAX month in the date table which is 12.

 

Capture.PNG

Hi @bhorvati,

The division must be made by the MAXIMUM month in you inventory table not the dste table.

Regards,
MFelix

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



@MFelix   I finally got it.   I have been having the same issue with a barrels per day formula.  I've been having to filter every report page for month to get my reports to work correctly.  This has been a HUGE help.  Thanks for taking the time.  Much appreciated. 

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.