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

July 28 - August 9 | Final Round of the Power BI Dataviz World Championships. This is your chance. Learn more

Reply
Anonymous
Not applicable

Date Function returning wrong Date

Hello All, 

 

Found a strange error in powerbi, where it is not able to convert month & year to a date for month 6 only:

 

below the dax:

 

Transaction Date =
var Year = vw_LoadSummaryINTL[Year]
var Month = vw_LoadSummaryINTL[Month]
var day = IF(vw_LoadSummaryINTL[Month] = 2,28,
IF(vw_LoadSummaryINTL[Month]= 9 , 30,
IF(vw_LoadSummaryINTL[Month]= 4 , 30,
IF(vw_LoadSummaryINTL[Month]= 5 , 30,
IF(vw_LoadSummaryINTL[Month]= 11 , 30, 31)))))

RETURN DATE(Year,Month,day)
 
For some reason, when the vw_LoadSummaryINTL[Month] = 6, the Transaction Date is 01/07/2020.
 
What am I missing?
 
Thank in advance!
2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Anonymous , Try var day like

var day = Switch(true(),
vw_LoadSummaryINTL[Month] = 2,28,
vw_LoadSummaryINTL[Month] in (4,6,9,11) , 30,
31)

 

or

Transaction Date =

 eomonth(date(vw_LoadSummaryINTL[Year], vw_LoadSummaryINTL[Month],1),0)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

Anonymous
Not applicable

@Anonymous 

There are small mistakes,  there is only 30 days in June. So change 5 to 6 in your formula:

IF(vw_LoadSummaryINTL[Month]= 6 , 30,
 
 
Or you may just use the simple version:
Transaction Date =
var day_= IF(vw_LoadSummaryINTL[Month] = 2,28,
IF(vw_LoadSummaryINTL[Month] in {4,6,9,11}, 30, 31))

RETURN DATE([Year],[Month],day_)
 
V-pazhen-msft_0-1620975454014.png


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

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

@Anonymous 

There are small mistakes,  there is only 30 days in June. So change 5 to 6 in your formula:

IF(vw_LoadSummaryINTL[Month]= 6 , 30,
 
 
Or you may just use the simple version:
Transaction Date =
var day_= IF(vw_LoadSummaryINTL[Month] = 2,28,
IF(vw_LoadSummaryINTL[Month] in {4,6,9,11}, 30, 31))

RETURN DATE([Year],[Month],day_)
 
V-pazhen-msft_0-1620975454014.png


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

Anonymous
Not applicable

Yes, sorry for the error, found that after posting here.

 

Regardless, I used your simple version and helped me a lot.

 

thank you for your help!

amitchandak
Super User
Super User

@Anonymous , Try var day like

var day = Switch(true(),
vw_LoadSummaryINTL[Month] = 2,28,
vw_LoadSummaryINTL[Month] in (4,6,9,11) , 30,
31)

 

or

Transaction Date =

 eomonth(date(vw_LoadSummaryINTL[Year], vw_LoadSummaryINTL[Month],1),0)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Fabric Community Sticker Design Challenge Barcelona Carousel

Fabric Community Sticker Challenge - Barcelona 2026

If you love stickers, then you will definitely want to check out our community sticker challenge, Barcelona edition!

July Power BI Update Carousel

Power BI Monthly Update - July 2026

Check out the July 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors