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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
TechR21
Helper V
Helper V

measure with automatic total number days of month

Hello,

 

Im using the following measure for a gauge to show the percentage of all runs of that month under 10 hours. This I do on a monthly base, so for januari i divide by 31.

 

Total % =
VAR less10 =
    CALCULATE ( COUNT ( 'Table'[Run] ), KEEPFILTERS ( 'Table'[Run] < 10 ) )
RETURN
    DIVIDE ( less10, 31 )

 

The gauge is on a page with different visuals, and Im using a filter to select the month that I want

 

How can I make this that it calculates the numbers of days in a month automatically, instead of putting a hard coded value in the measure?

 

 
 
 
 
1 ACCEPTED SOLUTION

Hi @TechR21 

 

Since you have a date filter, use the same date column in the variable:

VAR __DaysInMonth = DAY(EOMONTH(MAX('Date'[Date]),0))

vjingzhang_0-1675665743926.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

@TechR21 You could do something like this:

VAR __DaysInMonth = DAY(EOMONTH(TODAY(),0))

@ 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...

I see its not the correct percentage when i look for the data of januari. Is this because the today part in the measure?

VAR __DaysInMonth = DAY(EOMONTH(TODAY(),0))

 

for januari i have 16 days of the 31 that are below 10 hours, so I get a percentage of 51.61, but the gauge shows

TechR21_0-1675436476269.png

 

On the filter I selected all days of januari so this should be the range of calculation. If I select all the days of feb at the end of this month, I want the measure to show the percentage based on the days in feb

 

VAR __DaysInMonth = DAY(EOMONTH(MONTH(-1),0)) this works:)

Hi @TechR21 

 

Since you have a date filter, use the same date column in the variable:

VAR __DaysInMonth = DAY(EOMONTH(MAX('Date'[Date]),0))

vjingzhang_0-1675665743926.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.