Forum Discussion

Smitu30's avatar
Smitu30
New Member
5 years ago
Solved

How to dynamically number UserID and PurchaseDate

Hello.   Please see the below sample table. UserID PurchaseDate 000001 2020-07-01 000001 2020-07-12 000001 2020-08-05 000001 2020-08-21 000002 2020-07-09 000002 2020-08...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi Smitu30 

    If you want to have a dynamic sort, you need to build a measure and use Rankx function. 

    I build a table like yours to have a test.

    Measure:

     

    Measure = RANKX(FILTER(ALLSELECTED('Table'),'Table'[UserID]=MAX('Table'[UserID])),CALCULATE(MAX('Table'[PurchaseDate])),,ASC)

     

    Result is as below.

    Default:

    Filter Date>=2020/8/1:

    The max function in filter will return to a value = value in current row. So your filter will return to a table which values are all equal to current row.

    Ex: Filter(Table,'Table'[UserID]=MAX('Table'[UserID])), IF current row's UserID = 1,so it will return to the table as below and calculate the rank of 'Table'[PurchaseDate] in this table. And you can refer to the blog as below to learn more about context filter and row filter.

    For more info:

    Filter 

    row-context-and-filter-context-in-dax

    You can download the pbix file from this link: How to dynamically number UserID and PurchaseDate

     

    Best Regards,

    Rico Zhou

     

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