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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

count with filter

Dear All,

 

I would like to count id if id date >= 01/07/2020 for both channel. The returned result will be 1 which is id 4. How can I write the measure column for this please help.

Thanks 

kazanim.PNG

1 ACCEPTED SOLUTION
MattAllington
Community Champion
Community Champion

it's quite tricky. You should write a measure, not a column. The principle in DAX is "filter first, evaluate second". So you could try this (I haven't tested it).

 

 

=
CALCULATE (
    SUMX ( values(tablename[id]), IF ( calculate(countrows ( tablename[id] )) > 1, 1 ) ),
    FILTER ( tablename, tablename[date] >= DATE ( 2020, 7, 1 ) )
)

 

 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

View solution in original post

6 REPLIES 6
MattAllington
Community Champion
Community Champion

it's quite tricky. You should write a measure, not a column. The principle in DAX is "filter first, evaluate second". So you could try this (I haven't tested it).

 

 

=
CALCULATE (
    SUMX ( values(tablename[id]), IF ( calculate(countrows ( tablename[id] )) > 1, 1 ) ),
    FILTER ( tablename, tablename[date] >= DATE ( 2020, 7, 1 ) )
)

 

 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.
Anonymous
Not applicable

Actually I missed a point in my question that some id has only one channel also I need to check on. For examble below table ,if id has two channles both has to be greater than 01/07/2020 and if only one channel then it has to be greater than 01/07/2020. So for below table it should return 2 which ids 2 and 4. Please help. Thank you

 

new.PNG

 

 

=
SUMX (
    VALUES ( Table[id] ),
    VAR countOfChannels =
        CALCULATE ( DISTINCTCOUNT ( Table[channel] ) )
    VAR countAfterDate =
        CALCULATE ( COUNTROWS ( FILTER ( Table, [date] > DATE ( 2020, 7, 1 ) ) ) )
    RETURN
        IF ( countOfChannels = countAfterDate, 1 )
)


* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.
Anonymous
Not applicable

Actually I am getting an error  Thanks syntax.PNG

There is nothing wrong with the syntax. What is the name of your table in the model?  Is it Table?  If not, you need to change "table" in this measure to match the name of your table. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.
Anonymous
Not applicable

Actually I did fix the formula but I got blank results. What is wrong with that can you tell me that please? Thank you

 

= SUMX (
    VALUES('Table'[id]);
       VAR countOfChannels 
        = CALCULATE(DISTINCTCOUNT ( 'Table'[channel] ) )
  VAR countAfterDate
       =CALCULATE ( COUNTROWS('Table');FILTER('Table';'Table'[date]> DATE(2020;7;1)))
    RETURN
       IF ( countOfChannels = countAfterDate;1)
)

 

 

 

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.