Forum Discussion
PowerBI COUNTIFS Function in Excel
- 4 years ago
I guess you are trying to create a calculated column.
Your formula would be easier to translate if you were using tables in Excel. This is how your formula would look with tables:
=COUNTIFS([ColumnG], [@ColumnG], [ColumnN],">"&[@ColumnN])
So, let's assume you have a table called Table and it has ColumnA, ColumnB, ...= VAR __CurrentG = 'Table'[ColumnG] VAR __CurrentN = 'Table'[ColumnN] RETURN CALCULATE ( COUNTROWS ( 'Table' ), FILTER ( 'Table', AND ( 'Table'[ColumnG] = __CurrentG, 'Table'[ColumnN] > __CurrentN ) ) )
I'll try to explain and if someone detects a mistake, please do correct me.
You have a row context where you see only one row at a time. That is your scope.
You don't have a filter context at this step.
By using CALCULATE, you create a new inner row context, and in order to pass values from the outer row context to the inner one, you define VAR __CurrentG and VAR __CurrentN.
In the inner row context, you use FILTER to keep only the rows that match your VARs.
And then COUNTROWS counts how many rows there are in the inner row context for each row in the outer row context.I'd recommend watching YouTube videos from Excel Is Fun and SQLBI on those topics.
I guess you are trying to create a calculated column.
Your formula would be easier to translate if you were using tables in Excel. This is how your formula would look with tables:
=COUNTIFS([ColumnG], [@ColumnG], [ColumnN],">"&[@ColumnN])
So, let's assume you have a table called Table and it has ColumnA, ColumnB, ...
=
VAR __CurrentG = 'Table'[ColumnG]
VAR __CurrentN = 'Table'[ColumnN]
RETURN
CALCULATE (
COUNTROWS ( 'Table' ),
FILTER (
'Table',
AND ( 'Table'[ColumnG] = __CurrentG, 'Table'[ColumnN] > __CurrentN )
)
)
I'll try to explain and if someone detects a mistake, please do correct me.
You have a row context where you see only one row at a time. That is your scope.
You don't have a filter context at this step.
By using CALCULATE, you create a new inner row context, and in order to pass values from the outer row context to the inner one, you define VAR __CurrentG and VAR __CurrentN.
In the inner row context, you use FILTER to keep only the rows that match your VARs.
And then COUNTROWS counts how many rows there are in the inner row context for each row in the outer row context.
I'd recommend watching YouTube videos from Excel Is Fun and SQLBI on those topics.
- Anonymous4 years agoNot applicable
Thank you for the response! I definitely think it's on the right track. However, Column G is in one table (main table) and column N is in another table (all measures). Would this formula still work?
- Anonymous4 years agoNot applicable
Nevermind, this worked perfectly! Thank you!