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
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

v-yangliu-msft
Community Support
Community Support

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
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.