Forum Discussion
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:
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
- Anonymous4 years ago
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 )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.
6 Replies
- AnonymousNot applicable
- amitchandak
Super User
Anonymous , Try like
New measure =
var SelectedDate = MAXX(allselected(Sheet1), Sheet1[Week])
var PreviousWeek = SelectedDate -1RETURN
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 formatmeasures
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- AnonymousNot applicable
Hi amitchandak and thanks for your reply.
Result with your measure:It shows correct values now, however. The other weeks are also calulated by themselves.
- tamerj1
Community Champion
Hi Anonymous
Would you please share a screenshot that illustrates the expected result. Thank you - AnonymousNot 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 )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.- AnonymousNot applicable
Hi and thank you for your response!
Worked like a charm. Much obliged!