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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
bo_wang5
Helper II
Helper II

sorting by most current date range fiscal year and quarter

I'm using a custom date table to convert my dates to Fiscal Year and Quarter, "YYYY-QQ" in power query. I'd like then to only filter this data to most current 10 quarters. since "YYYY-QQ" is not a date data type, how would I sort and tell power query that I'd like to see the 10 most current as new data is loaded in each quarter without manually filtering the most recent data.

1 ACCEPTED SOLUTION
v-yingjl
Community Support
Community Support

Hi @bo_wang5 ,

You can try this query to filter lastest top10 value for each FY date:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XdJBDoMwDETRu7Cmwh5ISc6CuP81CF1U/rMLehrHGXFdi0K5nVvGsr5nfSLnaX7e6x8bTLCE7TQGD6B4YyvYfZ0vkFNPBmGdxuAAygsoOmxs1noyiupVUcvkH+8WNj6MG7mRTWtRmb5YrSrl2i1rew1j3qwg26OVZAsLZct+jIn3Aw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"FY Date" = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"FY Date", type text}, {"Value", Int64.Type}}),
    #"Grouped Rows" = 
        Table.Group(
            #"Changed Type", {"FY Date"}, 
                {
                    {
                        "Data", each
                        Table.SelectRows( 
                            Table.AddIndexColumn(
                                Table.Sort(_,{"Date",Order.Descending}),"Index",1,1),
                                each [Index] <= 10
                        )
                            , type table [Date=nullable date, FY Date=nullable date, Value=nullable number, Index = nullable number]
                    }
                }
        ),
    #"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Date", "Value"}, {"Date", "Value"})
in
    #"Expanded Data"

vyingjl_0-1648534096713.pngvyingjl_1-1648534108909.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-yingjl
Community Support
Community Support

Hi @bo_wang5 ,

You can try this query to filter lastest top10 value for each FY date:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("XdJBDoMwDETRu7Cmwh5ISc6CuP81CF1U/rMLehrHGXFdi0K5nVvGsr5nfSLnaX7e6x8bTLCE7TQGD6B4YyvYfZ0vkFNPBmGdxuAAygsoOmxs1noyiupVUcvkH+8WNj6MG7mRTWtRmb5YrSrl2i1rew1j3qwg26OVZAsLZct+jIn3Aw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t, #"FY Date" = _t, Value = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}, {"FY Date", type text}, {"Value", Int64.Type}}),
    #"Grouped Rows" = 
        Table.Group(
            #"Changed Type", {"FY Date"}, 
                {
                    {
                        "Data", each
                        Table.SelectRows( 
                            Table.AddIndexColumn(
                                Table.Sort(_,{"Date",Order.Descending}),"Index",1,1),
                                each [Index] <= 10
                        )
                            , type table [Date=nullable date, FY Date=nullable date, Value=nullable number, Index = nullable number]
                    }
                }
        ),
    #"Expanded Data" = Table.ExpandTableColumn(#"Grouped Rows", "Data", {"Date", "Value"}, {"Date", "Value"})
in
    #"Expanded Data"

vyingjl_0-1648534096713.pngvyingjl_1-1648534108909.png

 

Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

serpiva64
Solution Sage
Solution Sage

Hi,

You can try to add a column to your date table like this

if [Date]>DateTime.Date(( Date.AddMonths( DateTime.LocalNow(),-NrOfMonthes))) and [Date]<DateTime.Date(DateTime.LocalNow()) then 1 else 0

 

NrOfMonthes is a parameter 

serpiva64_0-1648226408927.png

 

 but i don't think it's so necessary 

 

serpiva64_0-1648222023387.png

If this post is useful to help you to solve your issue consider giving the post a thumbs up 

 and accepting it as a solution !

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

May 2025 Monthly Update

Fabric Community Update - May 2025

Find out what's new and trending in the Fabric community.