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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
BartStruyf
Regular Visitor

calculated colum to see if a an account has contacts with a certain role or not

Hello,

I'm struggeling to get this answer. 
My customers have mulptiple contacts, with different roles.  I want to summurize in a column if a customer has a contact with a certain rol or not.  
I have one table with :

 
Account IDRolHAS A?
1AY
1BY
2AY
2CY
3BN
3BN
 

I don't know how to write the right DAX-formula.

Thansk for you help,

Bart

4 REPLIES 4
Anonymous
Not applicable

// T is your table.

[Has A?] = // calc column
var __account = T[Account]
var __hasA =
	NOT ISEMPTY(
		FILTER(
			T,
			T[Account] = __account
			&&
			T[IDRol] = "A"
		)
	)
RETURN
	if( __hasA, "Y", "N" )

 

Best

D

mahoneypat
Employee
Employee

I agree it is better to right a measure when you can.  But also here is an expression for your calculated column.

 

HasA = if(calculate(Countrows(YourTable), All(YourTable), YourTable[Rol]="A", YourTable[Account ID]=Earlier(YourTable[Account ID]))>0, "Y", "N")

 

If this solution works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat

 





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


razmochaev
Helper I
Helper I

Hi @BartStruyf,

First of all, I would not recommend to use calculated column for this task. A measure would be more appropriate.

 

But to solve your problem you might do the following.

If you don't have separate dimension table for Roles you need to:

1. Create a measure [Num of unique Roles]: = DISTINCTCOUNT('YourTable'[IDRol])

2. Create a calculated column: = CALCULATE([Num of unique Roles];filter(VALUES('YourTable'[IDRol]);'YourTable'[IDRol]="A"))>0

Anonymous
Not applicable

Hi @razmochaev

And what if he wants to be able to slice by these values? Would you recommend a measure in this case as well?

Best
D

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors