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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Latest 4 weeks calculations with conditions based on a unique key

Dear all, 

 

I have a question that will be explained using the data sample below.

What I want to do is to get the sum of 'not calculated' with some conditions: the sum of 'not calculated' for each unique key have to be more than 2 for the last 4 weeks.

 

note: 

There's also a slicer for date in the Power BI, the result of the calculations will be used for:

- presented directly on cards (which the latest 4 weeks need to be adjusted with the selected dates on slicer)

- used for calculations of % as numerator

 

Unique keyDateNot calculated
A2/9/20211
B2/9/20211
C2/9/20211
D2/9/20210
A2/16/20211
B2/16/20211
C2/16/20210
A2/22/20211
B2/22/20210
A3/2/20211

 

Does anyone know any solution or approach regarding this?

Hope anyone can help me for this issue. Thank you!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , With help from week blog create a date table with week rank

Now try

Last 4  weeks = CALCULATE(divide(countx(filter(summarize(Table, Table[Unique key] , "_1", countx(filter(Table, Table[Not calculated] =1),[Unique key])),[_1]>2),[Unique key]), count(Table[Unique key]))

 

, FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-4 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

or use distinctcount

divide(countx(filter(summarize(Table, Table[Unique key] , "_1", countx(filter(Table, Table[Not calculated] =1),[Unique key])),[_1]>2),[Unique key]), distinctcount(Table[Unique key]))

 

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

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

@Anonymous , With help from week blog create a date table with week rank

Now try

Last 4  weeks = CALCULATE(divide(countx(filter(summarize(Table, Table[Unique key] , "_1", countx(filter(Table, Table[Not calculated] =1),[Unique key])),[_1]>2),[Unique key]), count(Table[Unique key]))

 

, FILTER(ALL('Date'),'Date'[Week Rank]>=max('Date'[Week Rank])-4 && 'Date'[Week Rank]<=max('Date'[Week Rank])))

 

or use distinctcount

divide(countx(filter(summarize(Table, Table[Unique key] , "_1", countx(filter(Table, Table[Not calculated] =1),[Unique key])),[_1]>2),[Unique key]), distinctcount(Table[Unique key]))

 

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, thank you for your answer, but I got different result from the expected. Here I have follow up questions regarding your solution if you don't mind.

 

1. I would like to sum the resulted countx on the summarize table. But, after I replace the first countx with sumx, I got error because of the "string data type" said PBI. 

 

2. I have tried to follow your web for the Week Rank, but it resulted in "1" for every rows. Therefore, I tried to use other alternative which is this dax, what do you think? 

FILTER(ALL('Calendar'), 'Calendar'[Date]>=SELECTEDVALUE('Calendar'[Date lookup])-25 && 'Calendar'[Date]<=SELECTEDVALUE('Calendar'[Date lookup])))
I used the dax above since the date are up to end of May, and the visualizations need to be adjusted based on the date chosen to give result for the last 4 weeks.
 
Once again, thank you and hope you can have further opiniion for this. 
Anonymous
Not applicable

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

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