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
joschultz
Helper III
Helper III

Dax Formula Number of days in a month

 

 

I am trying to figure out how to calculate where we will end up for the month based on average days sales.  So if we have an average of $1500  a day and we are 5 days in the month.  I need to calulate how may days are left in the month and then mutiply that by 1500 and add that to MTD sales.  But I would like this to be dynamic so that I do not need to change the month each month.

 

Thank you,

 

Joseph

4 ACCEPTED SOLUTIONS
v-jiascu-msft
Employee
Employee

Hi, Joseph

 

You should create a date table If you don't have a date column or a date table. It's easy. The formula is:

DateTable =
CALENDAR ( "2017-01-01""2017-12-31" )

Then there are two measures you can use.

1. Just current month:

DaysLeftCurrentMonth =
DATEDIFF ( NOW ()EOMONTH ( NOW ()0 )DAY )

2. Dynamic day and month respectively.

DaysLeftDynamicMoth =
DATEDIFF ( MIN ( 'DateTable'[Date] )ENDOFMONTH ( 'DateTable'[Date] )DAY )

Hope this would help.

Dax Formula Number of days in a month.JPG

 

 

Dax Formula Number of days in a month02.JPG

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Anonymous
Not applicable

Here is a formula that will do it if you don't wish to make a Date Table.

DaysinMonth = DAY( 
    IF(
        MONTH('Your Table'[Date Field]) = 12,
        DATE(YEAR('Your Table'[Date Field]) + 1,1,1),
        DATE(YEAR('Your Table'[Date Field]),  MONTH('Your Table'[Date Field]) + 1, 1)
    ) - 1
)

 

This just calculates the total number of days in the month.  You should be able to work it from there. 

View solution in original post

@joschultz

 

Hi, try this formula please. It could help.

DaysLeftCurrentQuarter =
DATEDIFF (
TODAY (),
EOMONTH (
TODAY (),
ROUNDUP ( MONTH ( TODAY () ) / 3, 0 )
* 3
- MONTH ( TODAY () )
),
DAY
)

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

@joschultz

 

Hi, Joseph

 

Thank you for marking my answers. You should add +1 with your entire first parameter. Or you can try the another one. They both works well. Good luck!

days in =
DATEDIFF (
    EOMONTH (
        TODAY (),
        ROUNDDOWN ( MONTH ( TODAY () ) / 3, 0 )
            * 3
            - MONTH ( TODAY () )
    )
        + 1,
    TODAY (),
    DAY
)
days in =
DATEDIFF (
    DATE ( YEAR ( TODAY () ), ROUNDDOWN ( MONTH ( TODAY () ) / 3, 0 ) * 3 + 1, 1 ),
    TODAY (),
    DAY
)
Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

16 REPLIES 16

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.