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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
capko
Helper II
Helper II

Countrows in a table created with a measure

Hello,

 

Let's say that I have a table 'A' and I have a measure that calculates a value for each line in the table. The initial table will be something like this:

 

 

| Column1 |  Column2 |
|---------|----------|
| Value 1 | Value 1' |
| Value 2 | Value 2' |
| Value 3 | Value 3' |

 

 

The code I'm using to add a column with the value of the measure mentioned before:

 

 

ADDCOLUMNS(A;"Measure";[Measure])

 

 

And the table once I've added the measure will be something like this: 

 

 

| Column1 |  Column2 |   Measure |
|---------|----------|-----------|
| Value 1 | Value 1' | Value 1'' |
| Value 2 | Value 2' | Value 2'' |
| Value 3 | Value 3' | Value 3'' |

 

 

NowI would like to add a filter and to count the number of elements with a criteria based on the measure value and on one of the columns. I've tried to create a measure as follows:

 

Final_Value = 
VAR A = ADDCOLUMNS(A;"Measure";[Measure])
RETURN CALCULATE(COUNTROWS(FILTER(A;A[Column1]="Test_String" && [Measure]>7)))

 

But this is not working. Does someone know how to apply a filter and how to count the number of rows when a table is created this way ?

5 REPLIES 5
Adamboer
Responsive Resident
Responsive Resident

The issue with your measure is that you are trying to reference the table A within the FILTER function, but the table A has not been defined in the measure. You defined the table A only within the ADDCOLUMNS function.

Here is a modified measure that should work:


Final_Value =
VAR A = ADDCOLUMNS(A;"Measure";[Measure])
RETURN
COUNTROWS(
FILTER(
A,
[Column1] = "Test_String" && [Measure] > 7
)
)

 

In this measure, we define the table A using the ADDCOLUMNS function as before, but now we use this table within the FILTER function to count the number of rows that meet the specified criteria. Note that we reference the [Column1] and [Measure] columns directly, without prefixing them with the table name, since they have been added to table A using ADDCOLUMNS.

It does not work but I think I know why (I don't know how to solve it but I know why it doesn't work). Actually I need to, first of all, apply the filter only on the 'Measure' column and after that to count the number of rows with the criteria on 'Column1'.

 

My bad, it was a mistaje on my side on my first post.

As I explained before it does not work but I think I know why (I don't know how to solve it but I know why it doesn't work). Actually I need to, first of all, apply the filter only on the 'Measure' column and after that to count the number of rows with the criteria on 'Column1'.

 

My bad, it was a mistaje on my side on my first post.

 

So I tried this approach:

 

 

Final_Value = 
VAR A1 = ADDCOLUMNS(A;"Measure";[Measure])
VAR B1 = FILTER(A1;[Measure]>7)
RETURN 
CALCULATE(COUNTROWS(FILTER(B1;[Column1]="Test_String"))

 

But the calculation never ends...

Greg_Deckler
Community Champion
Community Champion

@capko Try:

Final_Value = 
VAR A = ADDCOLUMNS(A;"__Measure";[Measure])
RETURN COUNTROWS(FILTER(A;[Column1]="Test_String" && [__Measure]>7))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

I tried it but it's not filtering using the measure as it should

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors