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
Anonymous
Not applicable

Why does DISTINCTCOUNT of Months have 1 extra count?

Hi,

 

I've built a Calendar table for use in a Power BI report and I want to create a measure that counts the number of months for the selected year in 2 slicers. Months & Years in the future are hidden/blank in Calendar. However, when I select Years from 2019 onwards my count has an extra value

 

ie my Measure (MthCount) counts as follows with no Months selected:

2017 - 12 months

2018 - 12 months

2019 - 8 months

2020 (onwards) - 1 month

 

Then, when I select say 2 Months my Measure counts correctly ie 2.

(see attached pics)

 

CalendarYear1.jpgCalendar2Mths.jpgMeasureMthCount.jpgCalendarTbl.jpg

 

Does anyone know what's going on here?

 

Cheers

 

 

1 ACCEPTED SOLUTION
d_gosbell
Super User
Super User

I think this is because you are force an explicit blank into that column for future periods. So 2020 has one blank for the TDYearMonth column and 2019 has 7 "real" months plus the blank which equals 8. So you could either filter out the blanks or use a different approach like creating a separate columns for filtering and counting.

MthCount = COUNTROWS( FILTER(VALUES('Calendar'[TDYearMonth]), NOT(ISBLANK('Calendar'[TDYearMonth]))))


or create a calculated column like the following:

IsPriorDate = IF( 'Calendar'[Date] <= Today(), 1,0)

Then you could add IsPriorDate = 1 as a Page or Report level filter.

View solution in original post

2 REPLIES 2
d_gosbell
Super User
Super User

I think this is because you are force an explicit blank into that column for future periods. So 2020 has one blank for the TDYearMonth column and 2019 has 7 "real" months plus the blank which equals 8. So you could either filter out the blanks or use a different approach like creating a separate columns for filtering and counting.

MthCount = COUNTROWS( FILTER(VALUES('Calendar'[TDYearMonth]), NOT(ISBLANK('Calendar'[TDYearMonth]))))


or create a calculated column like the following:

IsPriorDate = IF( 'Calendar'[Date] <= Today(), 1,0)

Then you could add IsPriorDate = 1 as a Page or Report level filter.

Anonymous
Not applicable

@d_gosbell 

Brilliant! Thanks for that mate. I used your first solution ie filter inside my measure and it worked perfectly. Something I hadn't thought of in that forcing a BLANK basically created a 'value'. I'm still new to PBI so this is a good early learning experience.

 

Thanks again.

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.