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! Request now

Reply
Anonymous
Not applicable

COUNTROWS Duplicates Names with filter

Hi!

I'm currently stuck on this what i believe should be a simple endevour.

I am trying to count the duplicates Names within a table and i have a solution for that. Although, i want to count the duplicates from last week only.
Lets say i have week 24,25 & 26 data within my table. I only want to count the duplicates from week 25. Everything else should be blank or recieve zero value.

I've tried several ways but i still get values on all the weeks.
Help would be much appreciated!

-------------------------------------------------------------------------------------------------------------------------------------
Here is my working solution for all weeks:

Count Names 1 =
Var Names = [Name]
RETURN
CALCULATE(
COUNTROWS('Sheet1'),
all('Sheet1'),
'Sheet1'[Name] = Names
)

Here is my solution for highest week - 1 that doesn't seem to be working:

Count Names 2 =
var Names = Sheet1[Name]
var SelectedDate = MAX(Sheet1[Week])
var PreviousWeek = SelectedDate -1

RETURN

CALCULATE(
COUNTROWS('Sheet1'),
CALCULATETABLE(all('Sheet1')),
'Sheet1'[Name] = Names && 'Sheet1'[Week] = PreviousWeek
)



Kind Regards
D

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Please remove the ALL() filter:

New measure =
var SelectedDate = MAXX(allselected(Sheet1), Sheet1[Week])
var PreviousWeek = SelectedDate -1
RETURN
CALCULATE(
COUNTROWS('Sheet1'),
filter('Sheet1',
'Sheet1'[Name] = max('Sheet1'[Name] ) && 'Sheet1'[Week] = PreviousWeek
)

Eyelyn9_1-1657005384817.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Hi @Anonymous ,

 

Please remove the ALL() filter:

New measure =
var SelectedDate = MAXX(allselected(Sheet1), Sheet1[Week])
var PreviousWeek = SelectedDate -1
RETURN
CALCULATE(
COUNTROWS('Sheet1'),
filter('Sheet1',
'Sheet1'[Name] = max('Sheet1'[Name] ) && 'Sheet1'[Week] = PreviousWeek
)

Eyelyn9_1-1657005384817.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Hi and thank you for your response!
Worked like a charm. Much obliged!

tamerj1
Super User
Super User

Hi @Anonymous 
Would you please share a screenshot that illustrates the expected result. Thank you

Anonymous
Not applicable

 

@Anonymous , Try like

 

New measure =
var SelectedDate = MAXX(allselected(Sheet1), Sheet1[Week])
var PreviousWeek = SelectedDate -1

RETURN

CALCULATE(
COUNTROWS('Sheet1'),
filter(all('Sheet1'),
'Sheet1'[Name] = max('Sheet1'[Name] ) && 'Sheet1'[Week] = PreviousWeek
)

 

 

Also it is better to use a separate year week table or date table with week rank

 

New columns

Week Rank = RANKX(all('Date'),'Date'[Week Start date],,ASC,Dense)
OR
Week Rank = RANKX(all('Date'),'Date'[Year Week],,ASC,Dense) //YYYYWW format

 

measures

 

This Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])))
Last Week = CALCULATE(sum('Table'[Qty]), FILTER(ALL('Date'),'Date'[Week Rank]=max('Date'[Week Rank])-1))

 

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-Last-Week/ba-p/1051123
https://www.youtube.com/watch?v=pnAesWxYgJ8

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi @amitchandak and thanks for your reply.

Result with your measure:

DanZloo_0-1656664754063.png

It shows correct values now, however. The other weeks are also calulated by themselves.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors