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
Sebas2404
Frequent Visitor

costumer by last N order id's

For a sales visualisation I would like te calculate the sales for each costumer based on the last 5 sales.

Normally would could use the N last days from today. However I'm not intrested to use date but rather the last n orderID's.

 

Visual the calculation looks like this:

Sebas2404_1-1604569451087.png

I used:

 
TOPN_SU2 = TOPN(5, DimSU_Number, DimSU_Number[SU Number], DESC)
 
But this only delivers the last orderID's and is not filtered on costumer.
 image.png
3 REPLIES 3
amitchandak
Super User
Super User

@Sebas2404 , Create a column like this in order table

 

orderID Rank = rankx(filter('Table', [Customer] = earlier([customer])), [orderID],,asc,dense)

 

then try one of the two measures

Measure = CALCULATE(COUNT('Table'[Amount]) ,FILTER(('Table'),'Table'[orderID Rank] >=CALCULATE(max('Table'[orderID Rank])-5,ALLEXCEPT('Table','Table'[process]))))

 

or
Measure =
VAR __id = MAX ('Table'[Customer] )
VAR __rank = CALCULATE ( MAX('Table'[orderID Rank] ), ALLSELECTED ('Table' ), 'Table'[Customer] = __id )
CALCULATE ( sum ('Table'[Amount] ), VALUES ('Table'[Customer ),'Table'[Customer] = __id,'Table'[orderID Rank] = __rank )

 

My Latest Blog: https://community.powerbi.com/t5/Community-Blog/Important-Links-every-Power-BI-enthusiastic-should-b...

@amitchandak I Tried the formule orderID Rank = rankx(filter('Table', [Customer] = earlier([customer])), [orderID],,asc,dense) with new colom en that works fine. 

 

THANKS FOR THE FIRST STEP!

 

With the first measure ->  Measure = CALCULATE(COUNT('Table'[Amount]) ,FILTER(('Table'),'Table'[orderID Rank] >=CALCULATE(max('Table'[orderID Rank])-5,ALLEXCEPT('Table','Table'[process]))))

 

What do you mean with ALLEXCEPT('Table','Table'[process])))) ?

the process is new for me

 

@amitchandak some addition infortmation regarding the end result:

image.png

 

for each value of SU number I want to sum its own number with the last n SU number and there value for ech Su number in my filter range. 

 

Hopes this clarifies the question.

 

Thanks in advance

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.