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
Anonymous
Not applicable

COUNT with specific conditions - DAX formula help

Hello @all,

 

i could need some help on this given example:

 

25-04-_2019_10-19-58.jpg

What i'm looking for is the following:

Number (Count) of IDs for which type 1 exists and the requirement is fulfilled, but no type 2 exists yet.

 

Thanks in advance!

1 ACCEPTED SOLUTION
AnthonyTilley
Solution Sage
Solution Sage

i woudl create a calclated colunm that tells you which rows meet the criteria then use a measure to count.
 
calculated colunm 
CountSpec =
-- first get the id for thew row
var uid = Table1[id]
--then filter the table to just those with a matching id and get the max type
var ty = CALCULATE(MAX(Table1[type]),filter(table1,Table1[id]=uid))
-- then get the value for rquirment
var req = Table1[requirement check]
--nexct check to see if each of the rows meet the criteria
var reqcheck = IF(req = "Y", true(),false())
var tycheck = if(ty = 1, TRUE(),FALSE())

-- finally compare the two checks and return 1 if both are true

var ret = if(and(reqcheck,tycheck),1,0)

Return ret

measure
Measure = sum(Table1[CountSpec])




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

Proud to be a Super User!




View solution in original post

2 REPLIES 2
AnthonyTilley
Solution Sage
Solution Sage

i woudl create a calclated colunm that tells you which rows meet the criteria then use a measure to count.
 
calculated colunm 
CountSpec =
-- first get the id for thew row
var uid = Table1[id]
--then filter the table to just those with a matching id and get the max type
var ty = CALCULATE(MAX(Table1[type]),filter(table1,Table1[id]=uid))
-- then get the value for rquirment
var req = Table1[requirement check]
--nexct check to see if each of the rows meet the criteria
var reqcheck = IF(req = "Y", true(),false())
var tycheck = if(ty = 1, TRUE(),FALSE())

-- finally compare the two checks and return 1 if both are true

var ret = if(and(reqcheck,tycheck),1,0)

Return ret

measure
Measure = sum(Table1[CountSpec])




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

Proud to be a Super User!




Anonymous
Not applicable

it does exactly what i need it to, thank you!

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.