Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
10119166
Frequent Visitor

Count iterative rows meeting a specific condition

Hi I am trying to interatively count rows in PowerBI that meet a given condition.   If the values began in cell A2 in Excel, the equation starting in B2 would be: =countif($a$2:a2,a2)...  How would I do this in DAX or M?  Thank you for any help any one can provide!

 

Row      Column A   Column B

 2                    a                          1

 3                    a                          2

4                     a                          3

5                     b                         1

6                     b                         2

7                     b                         3

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@10119166  here is the dax , change column name and table name as per your data model

 

My Count = 
VAR __r = MAX( Table[Row] )
RETURN 
CALCULATE( 
    COUNTROWS( Table ), 
    ALLEXCEPT( 
        Table, 
        Table[Column A] 
    ), 
    Table[Row] <= __r 
)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

3 REPLIES 3
10119166
Frequent Visitor

Thank you so much for your help!  This worked great!

Anonymous
Not applicable

You can use the following for a new calculated column:

Calculated Column = 
var __CurrentRow = 'Table'[Row]
var __CurrentColumns = 'Table'[Column]
return

CALCULATE(
    COUNTROWS('Table'),
    FILTER(
        'Table',
        'Table'[Column] = __CurrentColumns
        &&
        'Table'[Row] <= __CurrentRow
    )
)

or the following as a measure 

Measure = 
CALCULATE(
    COUNTROWS('Table'),
    FILTER(
        ALL( 'Table'),
        MAX( 'Table'[Row] ) >= 'Table'[Row]
    ),
    VALUES( 'Table'[Column])
)
parry2k
Super User
Super User

@10119166  here is the dax , change column name and table name as per your data model

 

My Count = 
VAR __r = MAX( Table[Row] )
RETURN 
CALCULATE( 
    COUNTROWS( Table ), 
    ALLEXCEPT( 
        Table, 
        Table[Column A] 
    ), 
    Table[Row] <= __r 
)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.