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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
dvraan
Frequent Visitor

Calculate Days in Two Months Based on Start and End Date

 

EVALUATE
VAR StartDate = DATE(2024, 9, 17)   
VAR EndDate = DATE(2024, 10, 5)    

-- Find the last day of the start month (September)
VAR EndOfStartMonth = EOMONTH(StartDate, 0)

-- Calculate the number of days in the start month (September)
VAR DaysInStartMonth = DATEDIFF(StartDate, EndOfStartMonth, DAY) + 1

-- Calculate the number of days in the end month (October)
VAR StartOfEndMonth = DATE(YEAR(EndDate), MONTH(EndDate), 1)
VAR DaysInEndMonth = DATEDIFF(StartOfEndMonth, EndDate, DAY) + 1

-- Return the result
RETURN
    UNION (
        ROW ( "Month",  FORMAT(MONTH(StartDate), "mmmm", "en-US"), "Days", DaysInStartMonth ),
        ROW ( "Month", FORMAT(MONTH(EndDate), "mmmm", "en-US"), "Days", DaysInEndMonth )
    )

 

 without using format function i get correct month like 09,10 as month. but when i pass month(startDate) to format function returns only January as month. Any why it does that? 

Month Days

January14
January5

 

 

I want to get

Month Days

September14
October5
2 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

EVALUATE
VAR StartDate = DATE(2024, 9, 17)   
VAR EndDate = DATE(2024, 10, 5)    

-- Find the last day of the start month (September)
VAR EndOfStartMonth = EOMONTH(StartDate, 0)

-- Calculate the number of days in the start month (September)
VAR DaysInStartMonth = DATEDIFF(StartDate, EndOfStartMonth, DAY) + 1

-- Calculate the number of days in the end month (October)
VAR StartOfEndMonth = DATE(YEAR(EndDate), MONTH(EndDate), 1)
VAR DaysInEndMonth = DATEDIFF(StartOfEndMonth, EndDate, DAY) + 1

-- Return the result
RETURN
    UNION (
        ROW ( "Month",  FORMAT(StartDate, "mmmm", "en-US"), "Days", DaysInStartMonth ),
        ROW ( "Month", FORMAT(EndDate, "mmmm", "en-US"), "Days", DaysInEndMonth )
    )

View solution in original post

v-kaiyue-msft
Community Support
Community Support

Hi @dvraan ,

 

When using FORMAT(MONTH(StartDate), “mmm”, “en-US”), it interprets MONTH(StartDate) as a number (e.g., 9 for September) and formatted as a date. To get the correct month name, you should format the entire date, not just the month number. You can refer to the program provided by lbendlin .

 

vkaiyuemsft_0-1726638852289.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
dvraan
Frequent Visitor

Thanks @v-kaiyue-msft and @lbendlin both answers were helpful. Thanks again

v-kaiyue-msft
Community Support
Community Support

Hi @dvraan ,

 

When using FORMAT(MONTH(StartDate), “mmm”, “en-US”), it interprets MONTH(StartDate) as a number (e.g., 9 for September) and formatted as a date. To get the correct month name, you should format the entire date, not just the month number. You can refer to the program provided by lbendlin .

 

vkaiyuemsft_0-1726638852289.png

 

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.

lbendlin
Super User
Super User

EVALUATE
VAR StartDate = DATE(2024, 9, 17)   
VAR EndDate = DATE(2024, 10, 5)    

-- Find the last day of the start month (September)
VAR EndOfStartMonth = EOMONTH(StartDate, 0)

-- Calculate the number of days in the start month (September)
VAR DaysInStartMonth = DATEDIFF(StartDate, EndOfStartMonth, DAY) + 1

-- Calculate the number of days in the end month (October)
VAR StartOfEndMonth = DATE(YEAR(EndDate), MONTH(EndDate), 1)
VAR DaysInEndMonth = DATEDIFF(StartOfEndMonth, EndDate, DAY) + 1

-- Return the result
RETURN
    UNION (
        ROW ( "Month",  FORMAT(StartDate, "mmmm", "en-US"), "Days", DaysInStartMonth ),
        ROW ( "Month", FORMAT(EndDate, "mmmm", "en-US"), "Days", DaysInEndMonth )
    )

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.