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
MrGlenn
Helper I
Helper I

First Day Of The Month

Hello,

 

I have these variables

VAR ReportEndOfMonth = EOMONTH(DATE (YEAR(TODAY()), MONTH(TODAY()) -1, DAY(TODAY()) ), 0)
VAR ReportStartOfMonth =  DATE (YEAR(ReportEndOfMonth), MONTH(ReportEndOfMonth) , DAY(1) )

ReportEndOfMonth gives me 31/07/2022, which is correct.
ReportStartOfMonth gives me 31/07/2022, which is wrong.

If I change ReportStartOfMonth to

VAR ReportStartOfMonth =  DATE (YEAR(ReportEndOfMonth), MONTH(ReportEndOfMonth) , DAY(2) )

 ReportStartOfMonth gives me 01/07/2022.

Ideas of what is going wrong?

1 ACCEPTED SOLUTION
ribisht17
Super User
Super User

@MrGlenn 

 

Inside DAY(), there should be a date or replace it with 1 only (instead of DAY(1))

 

Regards,

Ritesh

Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users 

View solution in original post

2 REPLIES 2
transform99
Resolver I
Resolver I

DAX has its own DAY calculation:

DAY function (DAX) - DAX | Microsoft Docs

 

"Returns the day of the month, a number from 1 to 31."

 

To my understanding, you're feeding it DAY(1). The Serial codes are the same between Excel and PowerBI (e.g. 44617 = 25/02/2022).

 

What PowerBI is doing is taking this as [Serial Value 1] = 31/12/1899. That's returning DAY(31/12/1899) which returns the day of the month (31). This also explains why Serial Value 2 = 01/01/1900, and returns day of month (1).

 

A simple solution should be to amend your variable to this:

VAR ReportStartOfMonth =  DATE (YEAR(ReportEndOfMonth), MONTH(ReportEndOfMonth) , 1 )

 

ribisht17
Super User
Super User

@MrGlenn 

 

Inside DAY(), there should be a date or replace it with 1 only (instead of DAY(1))

 

Regards,

Ritesh

Mark my post as a solution if it helped you| Munde and Kudis (Ladies and Gentlemen) I like your Kudos!! !!
My YT Channel Dancing With Data !! Connect on Linkedin !!Power BI for Tableau Users 

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.