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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
jsteinigen
Frequent Visitor

DAX expression for a new calculated column counting all rows in the table with same value in column

Hello! 

 

I can't figure out how to compare the value of the current cell in a column with the rest of the value of that column. What I mean is, I understand that the calculation for the new column is done one row at a time, iterating through the whole table, right? Therefore, I want to take the 3rd column in the 1st row and compare it to the 3rd column in all other rows and count the number of rows that contain the same value, then write that number in the new calculated column for the first row and move on to the next row until the table is done. But how do I address the first (n-th) row 3rd column cell to compare it to all other rows' 3rd column cells to count those that match?

 

index   random   3rd_column    new_calculated

   1         ...                 A                     4

   2         ...                 A                     4

   3         ...                 A                     4

   4         ...                 A                     4

   5         ...                 B                     2

   6         ...                 B                     2

   7         ...                 C                     3

   8         ...                 C                     3

   9         ...                 C                     3

   10       ...                 D                     1

 

Any help how to count the rows with the same value in 3rd_colum to write the value into new_column of that row with a DAX function would be appreciated. 

 

Cheers

Jens

1 ACCEPTED SOLUTION
jsteinigen
Frequent Visitor

Somehow I tend to answer my own questions here. I figured it out now: 

 

new_calculated = COUNTROWS(FILTER('current table', 
(EARLIER('current table'[3rd_column]) = 'current table'[3rd_column])))

 

View solution in original post

1 REPLY 1
jsteinigen
Frequent Visitor

Somehow I tend to answer my own questions here. I figured it out now: 

 

new_calculated = COUNTROWS(FILTER('current table', 
(EARLIER('current table'[3rd_column]) = 'current table'[3rd_column])))

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors