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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
mrg64
Frequent Visitor

Create a custom column in query mode containing the period in format "YYYY-MM" from a date column

Hello,

 

In query mode I've created a new custom column containing the period "YYYY-MM" from another date column (InvoiceDelivery Date):

Transacton period=Number.ToText(Date.Year([InvoiceDeliveryDate]))&"-"&Number.ToText(Date.Month([InvoiceDeliveryDate]))

My problem is that I've got 2018-1 as a result instead of 2018-01, 2018-2 instead of 2018-02 and so on.

Later I'm sorting my charts on this period column and it results in 2018-1, 2018-10, 2018-02, 2018-03 and so on. I want it look like 2018-01, 2018-02, 2018-03 ... instead

 

I've tried to user the "format" command instead but this is not accepted in the query edit mode. got the message Expression.Error: The name 'FORMAT' wasn't recognized. 

TransactionPeriod = FORMAT(Lagerhyra[InvoiceDeliveryDate];"YYYY-MM")

 

I have to create the new period column during the query since I use the period field in a "group by" command in the same query!

 

Thanks in advance for all your help!

1 ACCEPTED SOLUTION
PattemManohar
Community Champion
Community Champion

@mrg64 Please try this...

 

Transaction Period =Text.Combine({Date.ToText(Date.From([InvoiceDeliveryDate]), "yyyy"), "-", Date.ToText(Date.From([InvoiceDeliveryDate]), "MM")})




Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




View solution in original post

3 REPLIES 3
Anonymous
Not applicable

@mrg64,

In addition to other's post, you can only use your second formula in DAX. As shown in the following example, you can create a calculated column in Power BI data view.
1.PNG

Regards,
Lydia

PattemManohar
Community Champion
Community Champion

@mrg64 Please try this...

 

Transaction Period =Text.Combine({Date.ToText(Date.From([InvoiceDeliveryDate]), "yyyy"), "-", Date.ToText(Date.From([InvoiceDeliveryDate]), "MM")})




Did I answer your question? Mark my post as a solution!

Proud to be a PBI Community Champion




Thanks a lot, it works perfect Smiley Happy

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.

Top Solution Authors