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
kfschaefer
Helper IV
Helper IV

Determine number of days in month

How do I determine the number of days in a month for each mtd to calculated the Target value?

10 REPLIES 10
kfschaefer
Helper IV
Helper IV

I need to calcuate the Target value per month and this would be determined by the number of days in each month

 

Looking for the correct syntax - 

if Jan = 31 then target/31 for the target value.

 

How do I determine the begin and end dates of each month and the number of days within each month?

Greg_Deckler
Super User
Super User

You could create a separate "Month" table like:

 

Month,Days
January,31
February,28
March,31

etc. and then create a measure to sum the [Days] column.

 

Not entirely sure what you are going for, a little context and data would help.


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

If you have a date table containing all the dates you should be able to create a measure that countrows on you date value this should return the number of days.
/sdjensen

is there dax code to create such a table and how do I implent it?

Loads of examples on the web on how to create a date table with power query. Just need a little googling. You could try this page https://www.powerquery.training/portfolio/dynamic-calendar-table/
/sdjensen

thanks for the suggestion , however, I do I do it in DAX?

 

I have a field called createDate (dates)  How do I use this field in an existing PowerBI Query to count the rows of days per each month worth of data?

 

Capture.PNG

Right, in Desktop, use an Enter Data query to build your Month table. Then in your existing table in Desktop create a new column in your data model with a formula like:

 

MonthName = FORMAT([createDate],"MMMM")

Relate the two tables on the MonthName columns and create your measure.


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

Alternatively, in M you can use Date.DaysInMonth

 

https://msdn.microsoft.com/en-us/library/mt260645.aspx

 

Date.DaysInMonth( DateTime.FromText("2012-03-01")) equals 31

what is the correect syntax for count(datez)????

On my phone right now but it should be something like this. Let's say you have a table containing all your dates that is called dates and you have a column containing all the dates called dateskey.

Number of days = countrows(dates, dates[dateskey])

/sdjensen

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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