Forum Discussion
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, Month Number
My goal is to have the sales for the latest three month of the current year, compared to the same three month the year before
My sales export is back to November 2021
What I did :
I used Record.Field along with Table.Max to get the highest value in my column Year and I did the same to get the Year -1
Now I would like to keep the latest three months but am not sure how to do it
Overall, if you have a suggestion to help me to reach my goal I'll be happy
Daniel
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))- Anonymous4 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.
3 Replies
- ronrsnfldSuper User
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)) - AnonymousNot applicable
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.
- AtoBIRegular Visitor
ronrsnfld thanks for your solution it worked for me
Anonymous thanks for your time and proposition. However, if am not mistaken, your solution works if I want to keep the last three months on a specific year. I wanted to keep the last three months of the current year and the same three months of the past year
Thanks all