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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
ClemFandango
Advocate II
Advocate II

Logic query for IF, AND, || with CALCULATE and COUNTROWS function

Hi all,

 

I am sure this is very simple, but I am really struggling with this bit of logic for CALCULATE, COUNTROWS & FILTER Functions. I have the following table called 'Test'

 

TypeActual EndPlanned End
122/10/24 
122/10/24 
225/10/24 
323/10/24 
4 22/10/24

 

If today was the 31st Oct, then I would like to count all of the rows (that were last week of the 31st Oct) as per the conditions below.
The result that I am hoping to achieve would be 5 i.e counting all of the rows above with dates.


I want to do the following calculation for everything that is 'type' = "1", "2", "3"

 

 

Completed Lasttwk = CALCULATE(
COUNTROWS(test),
FILTER(
test,
test[Status] = "Completed"
&& WEEKNUM(test[Actual End])
= WEEKNUM(TODAY())-1
&& YEAR(test[Actual End])=YEAR(TODAY())
)
)

 


However if 'type' = "4" then do the following

 

Completed Lasttwk = CALCULATE(
COUNTROWS(test),
FILTER(
test,
test[Status] = "Completed"
&& WEEKNUM(test[Planned End])
= WEEKNUM(TODAY())-1
&& YEAR(test[Planned End])=YEAR(TODAY())
)
)

 


I am looking for a sum of the COUNTROWS for both of the above calculations.
Any ideas how i can apply this logic to correctly COUNTROWS of the 'Test' table.

 

Any ideas gratefully received

1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@ClemFandango , Try using 

 

Completed Lasttwk =
CALCULATE(
COUNTROWS('Test'),
FILTER(
'Test',
('Test'[Type] IN {1, 2, 3} && 'Test'[Status] = "Completed" && WEEKNUM('Test'[Actual End]) = WEEKNUM(TODAY()) - 1 && YEAR('Test'[Actual End]) = YEAR(TODAY()))
||
('Test'[Type] = 4 && 'Test'[Status] = "Completed" && WEEKNUM('Test'[Planned End]) = WEEKNUM(TODAY()) - 1 && YEAR('Test'[Planned End]) = YEAR(TODAY()))
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

2 REPLIES 2
bhanu_gautam
Super User
Super User

@ClemFandango , Try using 

 

Completed Lasttwk =
CALCULATE(
COUNTROWS('Test'),
FILTER(
'Test',
('Test'[Type] IN {1, 2, 3} && 'Test'[Status] = "Completed" && WEEKNUM('Test'[Actual End]) = WEEKNUM(TODAY()) - 1 && YEAR('Test'[Actual End]) = YEAR(TODAY()))
||
('Test'[Type] = 4 && 'Test'[Status] = "Completed" && WEEKNUM('Test'[Planned End]) = WEEKNUM(TODAY()) - 1 && YEAR('Test'[Planned End]) = YEAR(TODAY()))
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






@bhanu_gautam Quickest response ever!

Thanks so much - i think that has done it. I will give it closer look tomorrow and mark it as accepted. 

Huge thanks again

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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