The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
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 ?
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...
@capko Try:
Final_Value =
VAR A = ADDCOLUMNS(A;"__Measure";[Measure])
RETURN COUNTROWS(FILTER(A;[Column1]="Test_String" && [__Measure]>7))
I tried it but it's not filtering using the measure as it should