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

Number of days in month

Hello,

 

I need help with counting the days in each month. 

The report I'm working on is using data from a monthly point of view so i've created the calendar table by doing this:

 

MonthCalendar Dynamic = 
var FullCalendar = 
    ADDCOLUMNS(
        CALENDAR( DATE(LEFT(MIN(BO_FACTORY_BENCHMARK[MonthYearNum]),4),1,1), DATE(YEAR(TODAY()),12,31) ), 
        "Month Number", MONTH([Date]),
        "Year", YEAR([Date]),
        "Year-Month", LEFT(FORMAT([Date],"yyyyMMdd"),6),
        "Month Name", FORMAT([Date],"MMM"),
        "Year-MonthName", FORMAT([Date],"MMM" & " " & YEAR([Date])),
        "No of calendar days", 
    )

RETURN 
    SUMMARIZE(FullCalendar,[Month Number],[Year],[Year-Month],[Month Name],[Year-MonthName],[No of calendar days])

 

And for a formula i need to count the number days in each month (you can see the "No of calendar days"), is there a expression to do this?
My idea was to use the COUNTROWS on the datetable i create using calendar, but i don't know how to address it. 

Any advice is welcome 🙂

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

I also didn't see the expected behavior to reference the [Date] column from the CALENDAR function.  In any case, here is an example of an approach that will work with GROUPBY.

 

DateSummarize =
VAR datetable =
    ADDCOLUMNS (
        CALENDAR ( DATE ( 202111 )DATE ( 20211231 ) ),
        "MonthName"FORMAT ( [Date], "MMM" )
    )
RETURN
    GROUPBY ( datetable, [MonthName], "No of Days"COUNTX ( CURRENTGROUP ()1 ) )

 
Pat
 




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
mahoneypat
Employee
Employee

Based on your original expression, I thought you wanted a table with a single row for each month with the # of days.  Is that not the case?

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


mahoneypat
Employee
Employee

I also didn't see the expected behavior to reference the [Date] column from the CALENDAR function.  In any case, here is an example of an approach that will work with GROUPBY.

 

DateSummarize =
VAR datetable =
    ADDCOLUMNS (
        CALENDAR ( DATE ( 202111 )DATE ( 20211231 ) ),
        "MonthName"FORMAT ( [Date], "MMM" )
    )
RETURN
    GROUPBY ( datetable, [MonthName], "No of Days"COUNTX ( CURRENTGROUP ()1 ) )

 
Pat
 




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

@mahoneypat 
Hmm okay. I don't really understand. Is this a completely new table? which I would create a relationship to and get it via RELATED?
Is it possible to get it in a calculated column?

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.