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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
noah44
Helper I
Helper I

Getting Month and Year from a Datetime field with DirectQuery

Hello,

 

I have a report where I want to show hourly, daily, monthly and yearly data.

 

It all worked fine expect for the monthly overview.

 

I tried it like this:

DATEVALUE(MONTH(smrt_eigenverbrauch_wert[Zeit]) & "." & YEAR(smrt_eigenverbrauch_wert[Zeit]))
 
But it always gives me this error message:
Conversion failed when converting date and/or time from character string.
 
I used the same DAX on a report with imported data and there it worked fine.
 
Can someone help me?
1 ACCEPTED SOLUTION
noah44
Helper I
Helper I

Hi, 

 

thanks for your answers. Sadly they both did not work.

But I found a solution that works for me:

 

DATE(YEAR('Table'[date]), MONTH('Table'[date]), 1)

 

Best Regards

Noah

View solution in original post

4 REPLIES 4
noah44
Helper I
Helper I

Hi, 

 

thanks for your answers. Sadly they both did not work.

But I found a solution that works for me:

 

DATE(YEAR('Table'[date]), MONTH('Table'[date]), 1)

 

Best Regards

Noah

Anonymous
Not applicable

Hi  @noah44  ,

I tried your operation and found this error.

v-yangliu-msft_0-1622188709075.png

You can convert the "." inside to "/" so that it can be displayed.

DATEVALUE(MONTH(smrt_eigenverbrauch_wert[Zeit]) & "/" & YEAR(smrt_eigenverbrauch_wert[Zeit]))

v-yangliu-msft_1-1622188709078.png

 

Best Regards,

Liu Yang

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

Pragati11
Super User
Super User

Hi @noah44 ,

 

Have you tried something like this:

Date MMYYYY = FORMAT(ClothingSales[Date],"mmm-yyyy")
 
This calculation will also give you Month-Year part.
 
Thanks,
Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

Hi @Pragati11,

 

I tried this a while ago but apparently FORMAT can not be used with DirectQuery.

 

Thanks for your answer

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.