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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
GCH_Ryan
Frequent Visitor

Number per month when not all months have data

My data is a list of homes that will be sold and a projected date of when they will be sold. One of the columns is Gross Margin another is projected Sales Closing. I would like to have a card that shows the Gross Margin per month based on the number of months in a filtered number of years. For instance, if select 2018 on my slicer it will be SUM([GrossMargin]) / 12. If my slicer shows 2018 - 2020 the formula would be SUM([GrossMargin]) / 36. The issue I am running into is that we don't always have a home sale every month. I've tried creating a calendar table with a yyyy-mm column and relating that to my Sales Closing with a 1 to many relationship. I then created a count measure on the yyyy-mm column however when filtered by Sales Year, it only displays the count of months where there is a sale. For a stop gap I created this measure:

 

GMperMonth24 = CALCULATE(SUM('Future Sales'[Gross Margin]) / 24 , FILTER('Unit_Performance' , OR(YEAR(Unit_Performance[Sale Closing]) = 2018 , YEAR(Unit_Performance[Sale Closing] = 2019))))

 

I added that measure to a card, then disabled the interaction with the slicer on the page which works for those two years but I need to link this card to the other slicer. My idea is toreplace the  "24" with a count formula and ditch the Filter portion but I can't figure out how to get the right count of the number of total months within the selected number of years in the slicer. Any ideas? 

 

Edit 1

Example Report: I would like the card in Gross Margin $ per Month card in the upper left to reflect the average goss margin per month based on the number of total months in the period of years selected in the slicer. Because there are months with no sales, my Sales Closing dates are missing months and can't act as the driver for the number of months in the given year. Please let me know if there is specific sample data I can provide.

 

PBI_Margin.PNG

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

@GCH_Ryan

 

Hi , With your short explanation and without a sample, i assume that you want this:

 

 

NumberofMonthsSelected= (Year(LastDate(CalendarTable[Date]  ) )-Year(FirstDate(CalendarTable[Date] ) ) + 1)*12

 

Regards

 

Victor

 

 

 

 




Lima - Peru

View solution in original post

4 REPLIES 4
Vvelarde
Community Champion
Community Champion

@GCH_Ryan

 

Hi , With your short explanation and without a sample, i assume that you want this:

 

 

NumberofMonthsSelected= (Year(LastDate(CalendarTable[Date]  ) )-Year(FirstDate(CalendarTable[Date] ) ) + 1)*12

 

Regards

 

Victor

 

 

 

 




Lima - Peru

@Vvelarde This didn't work at first, and then I realized that my slicer was based on the Sales Closing Date, not the date from the calendar table. Once I made that change, this solution worked. Thank you! 

Greg_Deckler
Super User
Super User

Sample/example data is extremely helpful for solving these kinds of problems.

 

https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Thanks for the advice, I added a screen shot and tried to more clearly explain the problem I'm facing and my desired outcome. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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