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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
RvdHeijden
Post Prodigy
Post Prodigy

Countrows with filter in 2 columns

I have a formula that is almost done but it doesn't work just yet.

 

Aantal adressen =
CALCULATE(COUNTROWS(Adressen);Table[Plaats]="value A";'Table'[AP gebied naam]="value B")

 

This formula works but i dont have a value A and B, the values should reference to that row.

Actually the value A en B is different in each row because Value A is value 'Plaats' en Value B is 'AP gebied naam' for that row.

 

How can i fix my formula so that is refers to those 2 colums for each row ?

 

2018-04-09_1559.png

1 ACCEPTED SOLUTION

Hello,

 

My calculated column according to your sample given looks the following:

Countrows Earlier.PNG

 

If I use Countrows as a Measure putting them into PivotTable gives this result:

Countrows Earlier 2.PNG

 

I'm using an PowerPivot. And don't if this makes any difference.

 

Best regards.

View solution in original post

13 REPLIES 13
Greg_Deckler
Community Champion
Community Champion

It occurs to me that this might be better handled as a measure instead of a column. But, overall this seems like a similar issue in terms of creating a calculated column based upon other rows as my MTBF article. The trick is to use EARLIER.

 

See my article on Mean Time Before Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/3395...



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...

@Greg_Deckler

Im sorry but i dont think it has anything to do with your article, i briefly read it but it doesn't really help me in this case i think (or just dont get it, that is also possible)

Im looking for an simple anwer to the question but what would the formula be if it was a measure instead of a calculated column ?

 

 

@Greg_Deckler or anyone else know any solutions to this question ?

 

Anonymous
Not applicable

@RvdHeijden,

I am unable to view your image as it is corrupted. Could you please share dummy data if your table and post expected result here?

Regards,
Lydia

Goodday @Anonymous

The picture seems to work fine, just checked.

 

I need to know how many times a certain combination is in the table.

In excel it would be a sumproduct but in powerbi its a bit different.

 

In the example you can see that a city can be in 2 different area's (AP gebied naam) en i want to filter that.

So the formula should calculate (per Row) 

 

City                   AP gebied naam                

A                                 A

A                                 A

A                                 A

A                                 B

A                                 A

B                                 A

B                                 A

A                                 C

C                                 A

 

Result would be

 

City    AP gebied naam                     Count                     

A         A                                                4

A         B                                                1

A         C                                                1

B         A                                                2

C         A                                                1

 

Count the number of times Variable 1 and 2 are found in the same row.

 

@Anonymous@Greg_Deckler

 

Any ideas ? i thought this was a simple one but guess i was mistaken 🙂 

Hello,

 

generally I agree to @Zubair_Muhammad, Countrows should be fine if you filter afterwards after City and gebied name.

 

If you want to af it in a calculated column maybe try:

COUNTROWS(FILTER(FILTER(Table;Table['AP gebied naam']=EARLIER(Table['AP gebied naam']));Table[Plaats]=EARLIER(Table[Plaats])))

 

So you use a filter twice to reference a table.

 

Best regards.

@Floriankx

I wanted a calculated column but in your formula it only returns 1 as a value for all rows

 

Aantal adressen =
COUNTROWS(FILTER(FILTER('Table';'Table'[AP gebied naam]=EARLIER('Table'[AP gebied naam]));'Table'[Plaats]=EARLIER('Table'[Plaats])))

 

is there something wrong with the formula ?

@RvdHeijden

 

As a column...try

 

Column = CALCULATE(Count(Table1[ AP gebied naam]))

crows.png

Hi @RvdHeijden

 

Just drag the AP gebied naam column to a TABLE visual and Choose Count

see the attached file

 

row.png

@Zubair_Muhammad

what is your solution if i want it in a calculated column ?

Hello,

 

My calculated column according to your sample given looks the following:

Countrows Earlier.PNG

 

If I use Countrows as a Measure putting them into PivotTable gives this result:

Countrows Earlier 2.PNG

 

I'm using an PowerPivot. And don't if this makes any difference.

 

Best regards.

@Floriankx in the end it did work but i made a mistake.

Your formula was based on the fact that the data was in the same table, but the data was in another table

 

When i changed that it worked flawless, thank you for the help

 

 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors