Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

How to create an index

Hello, I would like to know how to create an index such index1 (see the example below) and that for each project in DAX (calculated column)

 

 

ProjectFiscal PeriodTargetDateindex1
A202001202008 
A202002202008 
A202003202008 
A202004202008 
A202005202008 
A202006202008 
A202007202008 
A2020082020081
A2020092020082
A2020102020083
A2020112020084
A2020122020085
A2021012020086
A2021022020087
A2021032020088
A2021042020089
B202001202007 
B202002202007 
B202003202007 
B202004202007 
B202005202007 
B202006202007 
B2020072020071
B2020082020072
B2020092020073
B2020102020074
B2020112020075
B2020122020076
  • Hi Anonymous ,

     

    Try this code for a calculated column:

    Index = IF('Table'[Fiscal Period] >= 'Table'[TargetDate], RANKX(FILTER('Table', 'Table'[Project] = EARLIER('Table'[Project]) && 'Table'[Fiscal Period] >= 'Table'[TargetDate]), 'Table'[Fiscal Period],,ASC), BLANK())
     

4 Replies

  • Anonymous why there are empty values in index? What is the logic? You can use Rank to get index.

     

    https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns

     

    I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

    Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.

    • Anonymous's avatar
      Anonymous
      Not applicable

      Good Question.

       

      If you look at project A, fiscal period start from 202001 and end in 202104.  As you can see, I want the index when the fiscal period is equal or greater to the target date.  So in project A, the target date is 202008, so we want an index starting at 1 for the fiscal period 202008 and the index continue to increase of one until 202104.  we need to do the same for each project.

      • camargos88's avatar
        camargos88
        Icon for Community Champion rankCommunity Champion

        Hi Anonymous ,

         

        Try this code for a calculated column:

        Index = IF('Table'[Fiscal Period] >= 'Table'[TargetDate], RANKX(FILTER('Table', 'Table'[Project] = EARLIER('Table'[Project]) && 'Table'[Fiscal Period] >= 'Table'[TargetDate]), 'Table'[Fiscal Period],,ASC), BLANK())