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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AtoBI
Regular Visitor

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

2 ACCEPTED SOLUTIONS
ronrsnfld
Super User
Super 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))

View solution in original post

v-stephen-msft
Community Support
Community Support

Hi @AtoBI ,

 

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

Selcet 'In the Previous...'

vstephenmsft_1-1641966837778.png

vstephenmsft_0-1641966824817.png

 

 

 

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.

 

View solution in original post

3 REPLIES 3
AtoBI
Regular Visitor

@ronrsnfld thanks for your solution it worked for me

@v-stephen-msft  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

v-stephen-msft
Community Support
Community Support

Hi @AtoBI ,

 

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

Selcet 'In the Previous...'

vstephenmsft_1-1641966837778.png

vstephenmsft_0-1641966824817.png

 

 

 

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.

 

ronrsnfld
Super User
Super 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))

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors
Top Kudoed Authors