Forum Discussion
Filter on the dimClient based on factSales
- Anonymous4 years ago
Hi Anonymous ,
Here's my solution.
1. Create a meaure to get the ranking. Calculate the ranking based on the date, and then the first one is the last purchase date.
Rank = RANKX ( FILTER ( ALL ( 'Sales' ), [Client ID] = MAX ( 'Sales'[Client ID] ) ), CALCULATE ( MAX ( 'Sales'[Date] ) ), , DESC, DENSE )If there are other categories, you can modify it to
Rank = RANKX ( FILTER ( ALL ( 'Sales' ), [Client ID] = MAX ( 'Sales'[Client ID] ) && [Category] = MAX ( 'Sales'[Category] ) ), CALCULATE ( MAX ( 'Sales'[Date] ) ), , DESC, DENSE )2.Create the following two measures to get the results.
Purchase Yesterday: = VAR _TODAY=DATE(2021,11,25) RETURN CALCULATE(DISTINCTCOUNT(Sales[Client ID]),FILTER('Sales',[Category]="A"&&[Date]=_TODAY-1&&[Rank]=1))Purchase Today: = VAR _TODAY = DATE ( 2021, 11, 25 ) RETURN CALCULATE ( DISTINCTCOUNT ( Sales[Client ID] ), FILTER ( 'Sales', [Category] = "A" && [Date] = _TODAY && [Rank] = 1 ) )Purchase Yesterday: = VAR _TODAY = DATE ( 2021, 11, 25 ) RETURN CALCULATE ( DISTINCTCOUNT ( Sales[Client ID] ), FILTER ( 'Sales', [Category] = "A" && [Date] = _TODAY - 1 && [Rank] = 1 ) )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.
Hi Anonymous ,
Here's my solution.
1. Create a meaure to get the ranking. Calculate the ranking based on the date, and then the first one is the last purchase date.
Rank =
RANKX (
FILTER ( ALL ( 'Sales' ), [Client ID] = MAX ( 'Sales'[Client ID] ) ),
CALCULATE ( MAX ( 'Sales'[Date] ) ),
,
DESC,
DENSE
)
If there are other categories, you can modify it to
Rank =
RANKX (
FILTER (
ALL ( 'Sales' ),
[Client ID] = MAX ( 'Sales'[Client ID] )
&& [Category] = MAX ( 'Sales'[Category] )
),
CALCULATE ( MAX ( 'Sales'[Date] ) ),
,
DESC,
DENSE
)
2.Create the following two measures to get the results.
Purchase Yesterday: = VAR _TODAY=DATE(2021,11,25)
RETURN CALCULATE(DISTINCTCOUNT(Sales[Client ID]),FILTER('Sales',[Category]="A"&&[Date]=_TODAY-1&&[Rank]=1))Purchase Today: =
VAR _TODAY =
DATE ( 2021, 11, 25 )
RETURN
CALCULATE (
DISTINCTCOUNT ( Sales[Client ID] ),
FILTER ( 'Sales', [Category] = "A" && [Date] = _TODAY && [Rank] = 1 )
)
Purchase Yesterday: =
VAR _TODAY =
DATE ( 2021, 11, 25 )
RETURN
CALCULATE (
DISTINCTCOUNT ( Sales[Client ID] ),
FILTER ( 'Sales', [Category] = "A" && [Date] = _TODAY - 1 && [Rank] = 1 )
)
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.