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
JustDavid
Helper IV
Helper IV

Assign current row fiscal period to previous but kept the EARLIEST as is

I have a table in PQ that shows only [FY Period].

 

I'd like to achieve the desired result shown as the print screen.

 

In other words, when [FY Period] is at the EARLIEST (in this case Q1FY25), return the value of [FY_Period].


However, if it's not the EARLIEST, then return the previous [FY_Period]

 

i.e. when it's Q2FY25, then return Q1FY25.  When it's Q3FY25, then return Q2FY25

 

Get Previous Fiscal But Kept the Earliest.png

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Your FY_Period column is in an unusable format - it does not sort well. So you need to add an index column.

 

lbendlin_0-1741049654325.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjR0izQyVYrVATKNEExjCDMWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FY_Period = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Desired Result", each #"Added Index"[FY_Period]{List.Max({0,[Index]-1})},type text)
in
    #"Added Custom"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.

 

 

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

Your FY_Period column is in an unusable format - it does not sort well. So you need to add an index column.

 

lbendlin_0-1741049654325.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjR0izQyVYrVATKNEExjCDMWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [FY_Period = _t]),
    #"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
    #"Added Custom" = Table.AddColumn(#"Added Index", "Desired Result", each #"Added Index"[FY_Period]{List.Max({0,[Index]-1})},type text)
in
    #"Added Custom"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the entire Source step with your own source.

 

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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.