Forum Discussion

Sebastian's avatar
Sebastian
Advocate III
10 years ago
Solved

create a Counter which adds +1

Hi all,

 

is it possible to create a new column which acts as Counter?

The Column starts with 1 and adds +1 in every row  or if a value in another Column change.

 

how could i realize this?

  • Anonymous's avatar
    Anonymous
    10 years ago

    I'm guessing this is related to the MonthIndex you were asking about in that other thread. Even if it is not you should still be able to use the same pattern. That's the only way I could come up with of sequentially incrementing a previous number that only changes on arbitrary rows. ImkeF might have another method though. I'll have to try that one out.

     

    Edit: now that I've said that, I just came up with a way to do it in DAX. See the link for the solution. I don't want to clutter up this thread with extra code if that solution doesn't quite apply to this question.

15 Replies

  • Vvelarde's avatar
    Vvelarde
    Community Champion

    Sebastian

     

    You can do it with a RankX; (depending of what type of values is your column)

     

    Counter = RANKX('Dates with Counter';'Dates with Counter'[Fecha];;ASC;Dense)

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks....

       

  • Hi Sebastian,

     

    If you want to have a column that numbers the row, you can go to Edit Queries and add an Indexed Column and choose it to start at 1.

    • Sebastian's avatar
      Sebastian
      Advocate III

      Ok, thanks for yout answer.

       

      And if the counter only should add +1 if the value in another field change?

       

      For example:

       

       

      Date                 Counter

      30.05.2016           1

      30.05.2016           1

      30.05.2016           1

      02.06.2016           2

      03.06.2016           3

      03.06.2016           3

      .

      .

      .

      .

      • Anonymous's avatar
        Anonymous
        Not applicable

        I'm guessing this is related to the MonthIndex you were asking about in that other thread. Even if it is not you should still be able to use the same pattern. That's the only way I could come up with of sequentially incrementing a previous number that only changes on arbitrary rows. ImkeF might have another method though. I'll have to try that one out.

         

        Edit: now that I've said that, I just came up with a way to do it in DAX. See the link for the solution. I don't want to clutter up this thread with extra code if that solution doesn't quite apply to this question.