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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
TuanNguyen0808
Regular Visitor

Convert Month & Fiscal year to Month & Fiscal year +1

Hi,

 

I often have to work with actual and budget data in Power BI. My budget data appears as the first screenshot where the fiscal year is from April to March containing budget figures in respective months, one column for fiscal year. That table contains budget data for multiple fiscal years.

During the course of data cleansing in Power Query, I have problem converting months from Jan to Mar.

For example, FY2023 & Jan should be come January 2024, not January 2023. So, I must save the result from Power Query to Excel, then insert another column named "Correct date" with a formula:

=IF(MONTH([@Date])<=3,[@Date]+366,[@Date])

(screenshot 2)

It's quite inconvenient.

 

Budget.jpg

 

Processed in Power Query.jpg

 

I don't want to continue that method anymore. Can anyone help me how I can convert months from Jan to Mar to correct years using DAX in Power Query w/o another step in Excel?

 

Thanks in advance.

2 ACCEPTED SOLUTIONS

I would encourage you to build your Date table the other way, starting with the calendar date and then calculating the fiscale date columns from that. But here is one way to do it from your existing columns. Put this expression into a custom column.

 

let
FD = Date.FromText([FY] & "-" & [Month] & "-" & "1"),
YearOffset = if Date.Month(FD)<=3 then 1 else 0,
OriginalDate = Date.ToText(FD, "MMMM") & " " & Text.From(Date.Year(Date.AddYears(FD, YearOffset)))
in
OriginalDate

 

ppm1_0-1699189224273.png

 

Pat

Microsoft Employee

View solution in original post

Note that with the method below, the only columns required are your FY and Month columns

 

Custom Column:

let 
  dt = Date.FromText([Month] & " " & Text.From([FY]))
in 
  if Date.Month(dt) <=3 then Date.AddMonths(dt,12) else dt

ronrsnfld_0-1699190025111.png

 

ronrsnfld_1-1699190067886.png

 

 

View solution in original post

6 REPLIES 6
TuanNguyen0808
Regular Visitor

Hi Pat,

 

This is the screenshot of the steps I did in Power Query using your suggestion. After inserting a custom column, the years are backward for Jan, Fed and Mar. I want the year value in circled part to move forward to 2023, not 2021.

 

Please help.

 

Screenshot 2023-11-04 054125.png

Note that with the method below, the only columns required are your FY and Month columns

 

Custom Column:

let 
  dt = Date.FromText([Month] & " " & Text.From([FY]))
in 
  if Date.Month(dt) <=3 then Date.AddMonths(dt,12) else dt

ronrsnfld_0-1699190025111.png

 

ronrsnfld_1-1699190067886.png

 

 

This method works well. Thank you very much.

I would encourage you to build your Date table the other way, starting with the calendar date and then calculating the fiscale date columns from that. But here is one way to do it from your existing columns. Put this expression into a custom column.

 

let
FD = Date.FromText([FY] & "-" & [Month] & "-" & "1"),
YearOffset = if Date.Month(FD)<=3 then 1 else 0,
OriginalDate = Date.ToText(FD, "MMMM") & " " & Text.From(Date.Year(Date.AddYears(FD, YearOffset)))
in
OriginalDate

 

ppm1_0-1699189224273.png

 

Pat

Microsoft Employee

Hi, Pat,

 

I have a Calendar table with the following code:

 

Calendar = ADDCOLUMNS(CALENDARAUTO(),

"Year", YEAR([Date]),

"Fiscal Year", IF(MONTH([Date]) <=3, Year([Date])-1, YEAR([Date])),

"Month number", MONTH([Date]),

"Period", IF(MONTH([DATE]) <=3,MONTH([Date])+9, month([Date])-3),

"Quarter", IF(MONTH([DATE])<=3,QUARTER([Date])+3,QUARTER([DATE])-1),

"Qtr", SWITCH(TRUE(),MONTH([date]) IN {4,5,6},"Qtr 1",MONTH([date]) IN {7,8,9},"Qtr 2",MONTH([date]) IN {10,11,12},"Qtr 3","Qtr 4"),

"Month name", FORMAT([Date],"MMM"))

 

Anyway, your solution today works well. Thank you very much.

ppm1
Solution Sage
Solution Sage

You can do it in Power Query with a custom column like this. Just shift the # of months forward or back based on your fiscal calendar.

 

= Date.ToText([Date], "MMMM") & " " & Text.From(Date.Year(Date.AddMonths([Date], -3)))

 

Pat

Microsoft Employee

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

Top Solution Authors
Top Kudoed Authors