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
Anonymous
Not applicable

Rank dublicates in specific time period

Hello, need help
I'm trying to rank phone calls for customer by time received and in specific time period.
For example:
I need to rank phone calls from same customer in 14 days from the last call.
First call was in 2.12.19 the second in 6.12.19 the third in 11.12.19, fourth 29.12.19 and the last one in 6.01.20
The expected output should be:
1. 2.12.19
2. 6.12.19
3. 11.12.19
1. 29.12.19 ( cause past more then 14 days from the last call in 11.12.19)
2. 6.01.20

Thanks
1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

Please create an index column in Query Editor and refer to the formulas as below.

tmp = 
var a = CALCULATE(MAX('Table'[date]),FILTER('Table','Table'[customer]= EARLIER('Table'[customer])&&'Table'[Index]=EARLIER('Table'[Index])-1))
var lastcall = IF(ISBLANK(a),'Table'[date],a)
var tmp = INT(DATEDIFF('Table'[date],lastcall,DAY)/14)
return
tmp

period = 
var period = CALCULATE(SUM('Table'[tmp]),FILTER('Table','Table'[customer] = EARLIER('Table'[customer])&&'Table'[Index] <= EARLIER('Table'[Index])))
return
period

rankx = Rankx(Filter('Table', [customer]=earlier ([customer])&&'Table'[period]=EARLIER('Table'[period])), [date], , desc)

 Result would be shown as below.

2.PNG

Pbix as attached.

 

Best Regards,

Jay

Community Support Team _ Jay Wang

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

5 REPLIES 5
v-jayw-msft
Community Support
Community Support

Hi @Anonymous ,

 

You can use DATEDIFF() function to defined periods. Please refer to the formulas below and check if the result achieve your expectation.

period = INT(DATEDIFF('Table'[date],CALCULATE(MAX('Table'[date]),FILTER('Table','Table'[customer]= EARLIER('Table'[customer]))),DAY)/14)
rankx = Rankx(Filter('Table', [customer]=earlier ([customer])&&'Table'[period]=EARLIER('Table'[period])), [date], , desc)

Result would be shown as below.

1.PNG
pbix as attached.

 

Best Regards,

Jay

Community Support Team _ Jay Wang

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
Anonymous
Not applicable

Thanks, almost there

I'll try to axplane the problem througt expected outcome

table below (new period for anothe 14 days from previous call

customer date PreviousCALL period rankx

A29/10/2019  01
A03/11/201929/10/201902
A26/11/201903/11/201911
A01/12/201926/11/201912
A10/12/201901/12/201913
A25/12/201910/12/201921
A02/01/202025/12/201922
A07/01/202002/01/202023

Hi @Anonymous ,

 

Please create an index column in Query Editor and refer to the formulas as below.

tmp = 
var a = CALCULATE(MAX('Table'[date]),FILTER('Table','Table'[customer]= EARLIER('Table'[customer])&&'Table'[Index]=EARLIER('Table'[Index])-1))
var lastcall = IF(ISBLANK(a),'Table'[date],a)
var tmp = INT(DATEDIFF('Table'[date],lastcall,DAY)/14)
return
tmp

period = 
var period = CALCULATE(SUM('Table'[tmp]),FILTER('Table','Table'[customer] = EARLIER('Table'[customer])&&'Table'[Index] <= EARLIER('Table'[Index])))
return
period

rankx = Rankx(Filter('Table', [customer]=earlier ([customer])&&'Table'[period]=EARLIER('Table'[period])), [date], , desc)

 Result would be shown as below.

2.PNG

Pbix as attached.

 

Best Regards,

Jay

Community Support Team _ Jay Wang

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.
littlemojopuppy
Community Champion
Community Champion

This is not going to be syntactically perfect (especially since I don't know the names of your tables), but should give you enough to work with.  This assumes there is a slicer for customers.  If call dates need to be within a certain range you can add criteria to the CALCULATETABLE statement to accommodate that.  Hope this helps!

RANKX(
	CALCULATETABLE(
		[Phone Calls],
		[Phone Calls].Customer = SELECTEDVALUE(Customer)
	),
	[Phone Calls].CallDate,
	TRUE
)



Anonymous
Not applicable

Thanks for response
I problem is to rank calls in cycle of 14 days . This what I have to rank all calls
Rankx(Filter(tablename, [customers]=earlier ([customer]) && [callDate]<earlier ([callDate]), [callDate], , desc)

I need to add one more rule than rank call in cycle of 14 days from last callDate.

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.