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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
danextian
Super User
Super User

Count number of instance based on multiple criteria

Hi All,

 

I've been trying to solve this on my own but  I just can't get the right DAX

 

Here's my scenario:

 

For each transaction type, the employee should meet the following mix -

 

transction type mix by employeeCount
Transaction Type 12
Transaction Type 21

 

This is going to be on a per month basis. If this mix is not hit by employee and by month, value should be "did not meet" else "did meet"

 

Here is a sample data - 

MonthEmployeeTransaction TypeCount
JanA1A
JanB1A
JanC1A
JanD1A
JanA2A
JanB2A
JanC2A
JanD1A
JanA2A
JanB2A
JanC2A
JanD2A
FebC1A
FebB1A
FebC1A
FebD1A
FebA2A
FebB2A
FebC2A
FebD1A
FebA2A
FebB2A
FebC2A
FebD2A

 

The resulting remarks should be something like this - 

MonthEmployeeType 1 Type 2Grand Totalremarks
JanA123did not meet
 B123did not meet
 C123did not meet
 D213did meet
FebA 22did not meet
 B123did not meet
 C224did not meet
 D213did meet

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
8 REPLIES 8
Phil_Seamark
Employee
Employee

Hi @danextian

 

Please try the following 4 calculated measures:

 

Type 1 = CALCULATE(COUNTROWS('Transactions'),'Transactions'[Transaction Type]="1")

Type 2 = CALCULATE(COUNTROWS('Transactions'),'Transactions'[Transaction Type]="2")

Grand Total = [Type 1] + [Type 2]

Remarks = IF([Type 1]>=2 && [Type 2]>=1,"did meet","did not meet")

 

pp.png


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi Phil,

 

Thanks for the reply. I tried this but it did not work. The measure calculates based on the whole data instead of a, for example, per criteria (by employee, by month). Since, for  the whole, the count for type 1 is not equal to 1 and for type 2 not equal to 2, the result is "did not meet".










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @danextian

 

Are the [type 1] and [type 2] measures ok and it's just the [result] measure that is wrong?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi @Phil_Seamark

 

Type 1 and Type are both okay - they both show the correct count. However, the calculated column is showing undesired result.]

 

If

Employee A

Type 1 = 2

Type 2 = 2

 

Then remarks = "did not meet"

Both criteria should be met. For this to be "did meet"  type 2 should be 1.  Cannot be less or equal than the set criteria.

 










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

PS: Both criteria should be met to have a "did meet" result.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Hi @danextian

 

If the [Remark] calculated measure needs to be an exact match you could try this

 

Remarks = IF([Type 1] = 2 && [Type 2] = 1,"did meet","did not meet")

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi @Phil_Seamark,

 

Thanks again for the prompt response. However, this still did not  work. It seems that this calculated column does not filter on a per employee and per month basis. I created the following matrix:

 

Row - Employee

Column - Trasaction Type

Value  =  Count of Transactions

 

 

The matrix shows that Employee A has 2 Type 1s and 1 Type 2s. Given the logic, this should have resulted to "did meet" but have not. 

 

I think we can use some sort of "x" function but not sure what the correct formula would be.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thanks. I will try this out.










Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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