cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
davidoz
Frequent Visitor

COUNTIFS equivalent to count the number of times two values appear in my data set

I have a data set of units of equipment. The user enters a start date, an end date, and the Unit Reserved for that job. Powerquery then expands the data to populate a new row for every day that unit will be used:

 

eg.

5/24/2022 SC-0037

5/25/2022 SC-0038

5/26/2022 SC-0039 etc... Please refer to screenshot below

 

Because the data entry is manual, I need to know if a particular unit is double booked on a certain date. In excel I would do this:

=COUNTIFS ( C:C , C2 , G:G , G2 ) 

 

I've searched for over an hour and I can't figure out how to do the same thing in PowerBI. Please help

 

davidoz_0-1653085160893.png

 

1 ACCEPTED SOLUTION
hnguy71
Solution Sage
Solution Sage

Hi @davidoz ,

 

I'm guessing you want a calculated column. You can build something like this:

CountDuplicates = 
VAR _Check = CALCULATE(COUNTROWS(YOUR_TABLE), FILTER(YOUR_TABLE, YOUR_TABLE[Date] = EARLIER(YOUR_TABLE[Date]) && YOUR_TABLE[UnitReserved] = EARLIER(YOUR_TABLE[UnitReserved])))
RETURN
IF(_Check > 1, 1, 0)

 

Let me know if that works.



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

View solution in original post

2 REPLIES 2
hnguy71
Solution Sage
Solution Sage

Hi @davidoz ,

 

I'm guessing you want a calculated column. You can build something like this:

CountDuplicates = 
VAR _Check = CALCULATE(COUNTROWS(YOUR_TABLE), FILTER(YOUR_TABLE, YOUR_TABLE[Date] = EARLIER(YOUR_TABLE[Date]) && YOUR_TABLE[UnitReserved] = EARLIER(YOUR_TABLE[UnitReserved])))
RETURN
IF(_Check > 1, 1, 0)

 

Let me know if that works.



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!
davidoz
Frequent Visitor

thank you! this worked perfectly!

Helpful resources

Announcements
June 2022 update 768X460.jpg

Check it out!

Click here to read more about the June 2022 updates!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Power BI Dev Camp Session 23 768x460.jpg

Check it Out!

Mark your calendars and join us on Thursday, June 30 at 11a PDT for a great session with Ted Pattison!

June 20 episode 7 with aka link 768x460.jpg

The Power BI Community Show

Join us on June 20 at 11 am PDT when Kim Manis shares the latest on Azure Synapse analytics, the Microsoft Intelligent Data Platform, and notable Power BI Updates from Microsoft Build 2022.

Top Solution Authors
Top Kudoed Authors