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
powerbiuser32
Regular Visitor

Count number of Days In current Month

Hello,

 

I need a measure to count the number of days in the current month, without the use of any tables etc. 

it should show whether this month has either 30, 31, 28 or 29 days. I want to use this number to calculate daily target from a fixed taraget value. 

 

Thank You!

1 ACCEPTED SOLUTION
Phil_Seamark
Employee
Employee

HI @Anonymous

 

You could try

 

Measure 2 = 
VAR t = TODAY()
RETURN  
    COUNTROWS(
        CALENDAR(
            FORMAT(t,"YYYY-MM-01") ,
            EDATE(FORMAT(t,"YYYY-MM-01"),1)-1
           )
    )

or

 

Measure 2 = 
VAR s = FORMAT(TODAY(),"YYYY-MM-01")
VAR e = EDATE(FORMAT(TODAY(),"YYYY-MM-01"),1)
RETURN int( e-s)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

4 REPLIES 4
Phil_Seamark
Employee
Employee

HI @Anonymous

 

You could try

 

Measure 2 = 
VAR t = TODAY()
RETURN  
    COUNTROWS(
        CALENDAR(
            FORMAT(t,"YYYY-MM-01") ,
            EDATE(FORMAT(t,"YYYY-MM-01"),1)-1
           )
    )

or

 

Measure 2 = 
VAR s = FORMAT(TODAY(),"YYYY-MM-01")
VAR e = EDATE(FORMAT(TODAY(),"YYYY-MM-01"),1)
RETURN int( e-s)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Anonymous
Not applicable

Hi @powerbiuser32

 

Try this measure:

Days_current_month =
DAY (
    IF (
        MONTH ( TODAY () ) = 12;
        DATE ( YEAR ( TODAY () ) + 1; 1; 1 );
        DATE ( YEAR ( TODAY () ); MONTH ( TODAY () ) + 1; 1 )
    )
        - 1
)

Regards.

Hi @Anonymous

 

Thank you. However the code returns a syntax error when copied an pasted.

 

Regards.

Anonymous
Not applicable

@powerbiuser32,

 

The code works, surely what is happening is that you have Power BI Desktop configured to use commas instead of semicolons as DAX separators, and for this reason @Phil_Seamark's code worked without problems (using commas). So you should simply change the semicolons by commas.

Here you have a tool to detect syntax errors in DAX and format with a recommended indentation, you can modify the separators in US / UK (comma) and Others (semicolon):

https://www.daxformatter.com

 

Regards.

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.