Forum Discussion

AtoBI's avatar
AtoBI
Regular Visitor
4 years ago
Solved

Keep the N highest/lowest value

Good Morning All,   I have a sales export file from SAP, which I wonder why they put this layout but anyway I have managed to do some transformations and I have now a column with the Year, Month, ...
  • ronrsnfld's avatar
    4 years ago

    To get the numbers of this year past 3 months and last year past three months you can create a custom filter to be used with Table.SelectRows.

     

    Assuming you have a "Date" column, something like:

     

    //create custom filter
    //current "last three months"
        dtCurrentEnd = Date.From(Date.StartOfMonth(DateTime.LocalNow())),
        dtCurrentStart = Date.From(Date.AddMonths(dtCurrentEnd,-3)),
    //previous year same three months
        dtPrevEnd = Date.AddYears(dtCurrentEnd,-1),
        dtPrevStart = Date.AddYears(dtCurrentStart,-1),
    
    //then filter the table
        yrToyr = Table.SelectRows(#"Changed Type", 
            each 
                ([Date] >=dtCurrentStart and [Date] < dtCurrentEnd) or 
                ([Date]>=dtPrevStart and [Date]< dtPrevEnd))
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi AtoBI ,

     

    You can filter the first three months data directly as follows.

    Selcet 'In the Previous...'

     

     

     

    Best Regards,

    Stephen Tao

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.