Forum Discussion

Syndicate_Admin's avatar
Syndicate_Admin
Icon for Administrator rankAdministrator
3 years ago

How to create a calculated column with cumulative count?

Good morning Power BI community

I'm looking to count a column in PBI, but I need this column to be accumulated, because I need to identify where it's the first time a piece of data is repeated to me, where it's the second time, where it's the third time and so on.

So far I have this formula like this, but it gives me the result blank

"Count1 = CALCULATE(

COUNT(ROSAinfo[Zimmer Acct # ]),
FILTER(
ALL(ROSAinfo),
AND(ROSAinfo[Zimmer Acct # ]=SELECTEDVALUE(ROSAinfo[Zimmer Acct # ]),
ROSAinfo[Install Date]=MIN(ROSAinfo[Install Date])
)
)
)"

I appreciate all the help you can give me with this.

6 Replies

  • Syndicate_Admin 

    Are you adding a cummulative column in the table "ROSAinfo" or a different one?
    Based on which column in which table do want to added cummulative column ?

    • Syndicate_Admin's avatar
      Syndicate_Admin
      Icon for Administrator rankAdministrator

      Yes, all through the same table, ROSAinfo, I need to cumulatively count the Zimmer Acct # that I have in that column, but by the criterion of the same field, for example, as I have done in Excel:

  • ichavarria's avatar
    ichavarria
    Icon for Solution Specialist rankSolution Specialist

    It seems like the formula you've provided is attempting to count the occurrences of a specific value in a column, but with the additional condition that it's the first time the value appears in the column based on the minimum install date.

    However, the formula you've provided may not be returning any values because the condition in the filter function is looking for rows where the Zimmer Acct # and Install Date are both equal to the selected value and the minimum install date, respectively. This may not always be true, especially if there are multiple rows with the same Zimmer Acct # and Install Date.

    To accumulate the count of occurrences of a value in a column, you can use the RANKX function in Power BI. The RANKX function assigns a rank to each value in a column based on a specified expression, and you can use this rank to determine the number of times a value has appeared.

    Here's an example of how you can modify your formula to use the RANKX function:

    Count1 = VAR SelectedZimmerAcct = SELECTEDVALUE(ROSAinfo[Zimmer Acct #]) RETURN RANKX( FILTER( ALL(ROSAinfo), ROSAinfo[Zimmer Acct #] = SelectedZimmerAcct ), MIN(ROSAinfo[Install Date]) )

    In this formula, we first store the selected Zimmer Acct # in a variable. Then, we use the FILTER function to return a table of all the rows in the ROSAinfo table where the Zimmer Acct # matches the selected value. We then use the RANKX function to assign a rank to each row based on the minimum install date. This rank represents the number of times the Zimmer Acct # has appeared in the table up to that point. Finally, we return this rank as the output of the measure.

    Note that this formula assumes that the Install Date column contains dates in a format that Power BI can recognize as such. If your Install Date column is not recognized as a date, you may need to convert it using the DATE function.


    If I answered your question, mark it as a solution. 
    https://www.linkedin.com/in/isaac-chavarria-artavia-38b982184/ 

    • Syndicate_Admin's avatar
      Syndicate_Admin
      Icon for Administrator rankAdministrator

      Thanks, now if it shows a data, but it shows me 1 in all the data.

      Suddenly the following screenshot gives a better idea of what I need to do in PBI:

      Here we see that we have the code 050776 that appears 3 times but, the first time it comes out, the formula counts it as 1, the second time it comes out, the formula counts it as 2 and the third time it comes out, the formula counts it as 3.

      Column AB has the cumulative count formula and column AC has the # of times the same code comes out in total.