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
JadeM
Frequent Visitor

Only calculate measure where rows meet specific condition in another column

Hi all,

 

I have the below measure which I am using to calculate whether staff movement is 'In' or 'Out'. It should show 'In' where there are two instatnces of one name in the filter view and 'Out' if a name only appears once. This measure needs to be dynamic so that the value of 'In' or 'Out' changes depending on the filters applied.

 

The below works correctly.

 

New Column = 
  var thisName = SELECTEDVALUE(Table1[Name])
  var nameCount = COUNTROWS(FILTER(ALLSELECTED(Table1), [Name] = thisName))
  var result = IF(nameCount > 1, "In", "Out")
  return IF(ISINSCOPE('Table1'[Name]), result)

 

 

I would now like to edit this measure so that the calculation only spits out 'In' or 'Out' where the value in the column 'Department' is 'Sales' or 'Marketing'. All otehr departments should be blank.

 

Here is an example of my data:

Table1 (no filters) John shows as 'In' in the new column as his name appears twice.

 

Name Department New Column
JohnSalesIn
JohnMarketingIn
JulieMarketingOut
JakeSalesOut
SimonIT 

If you then filter Department to show just Marketing (using a slicer on the same page), I would like John to change to 'Out' as there is now only one occurrence of the name John.

 

 

Name Department New Column
JohnMarketingOut
JulieMarketingOut

I do not want there to be a value next to Simon in IT as he is not in Marketing or Sales - how can I update the measure to incorporate this second requirement?
 
Thanks in advance.
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @JadeM ,

1.The measure can be modified to:

New Column =

  var thisName = SELECTEDVALUE('Table'[Name])

  var nameCount = COUNTROWS(FILTER(ALLSELECTED('Table'), [Name] = thisName))

  var result =

  IF(SELECTEDVALUE('Table'[Department]) = "Marketing" || SELECTEDVALUE('Table'[Department]) = "Sales",

  IF(nameCount > 1, "In", "Out"),BLANK())

  return IF(ISINSCOPE('Table'[Name]), result)

2.Set the Name or Department field to show items with no data so that when there is no data in the New Column column, the other columns can still be displayed normally.

vkaiyuemsft_1-1708585319502.png

 

The results obtained are shown below:

vkaiyuemsft_0-1708584856229.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @JadeM ,

1.The measure can be modified to:

New Column =

  var thisName = SELECTEDVALUE('Table'[Name])

  var nameCount = COUNTROWS(FILTER(ALLSELECTED('Table'), [Name] = thisName))

  var result =

  IF(SELECTEDVALUE('Table'[Department]) = "Marketing" || SELECTEDVALUE('Table'[Department]) = "Sales",

  IF(nameCount > 1, "In", "Out"),BLANK())

  return IF(ISINSCOPE('Table'[Name]), result)

2.Set the Name or Department field to show items with no data so that when there is no data in the New Column column, the other columns can still be displayed normally.

vkaiyuemsft_1-1708585319502.png

 

The results obtained are shown below:

vkaiyuemsft_0-1708584856229.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Community Champion
Community Champion

@JadeM Maybe:

New Column = 
  var thisName = SELECTEDVALUE(Table1[Name])
  var thisDept = SELECTEDVALUE(Table1[Department])
  var nameCount = COUNTROWS(FILTER(ALLSELECTED(Table1), [Name] = thisName))
  var result = SWITCH(TRUE(), thisDept = BLANK(), BLANK(), nameCount > 1, "In", "Out")
  return IF(ISINSCOPE('Table1'[Name]), result)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

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.

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.