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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Khushboo9966
Helper II
Helper II

PowerBI- How to write a calculate column when two tables have many to one relationship?

Hi, 

 

I have two table App(one relationship) and App Role(Many relationship). The direction of filteration is from App to App Role. This is a directquery model so RELATED, RELATEDTABLE are not supported functions. 

 

I have two columns(Role, Type) in App role table. I am writing a IF condition in App table something like below but I get only 0's. 

PrimaryB_Individual(A calculated column I created in App Role table): 

PrimaryB_Individual = IF(
    'App Role'[Role] = "PB" &&
    'App Role'[App Type]= "Individual",
    1, BLANK())

 

Level 1 is in App Table. This formula only gives me 0. 

Level 1 = IF(
    IF(not ISEMPTY( 'App'),
    SELECTEDVALUE('App Role'[PrimaryB_Individual])
) &&
    'App'[TBUS] <=24 &&
    'App'[NE] = "Existing",
        1,0
        )

 Any comments on what am I missing?

1 ACCEPTED SOLUTION
BeaBF
Super User
Super User

@Khushboo9966 Hi!

Try with:
Level 1 =
IF(
NOT ISEMPTY('App') && 
'App'[TBUS] <= 24 && 
'App'[NE] = "Existing", 
IF(
SUMX(FILTER('App Role', 'App Role'[Role] = "PB" && 'App Role'[App Type] = "Individual"), 1) > 0,
1,
0
),
0
)


BBF

View solution in original post

13 REPLIES 13
Khushboo9966
Helper II
Helper II

@BeaBF : Any thoughts?

BeaBF
Super User
Super User

@Khushboo9966 Hi!

Try with:
Level 1 =
IF(
NOT ISEMPTY('App') && 
'App'[TBUS] <= 24 && 
'App'[NE] = "Existing", 
IF(
SUMX(FILTER('App Role', 'App Role'[Role] = "PB" && 'App Role'[App Type] = "Individual"), 1) > 0,
1,
0
),
0
)


BBF

@BeaBF That worked! Thank you so much. 

 

If you don't mind, What is wrong in my DAX? 

@Khushboo9966 sure.
In your original formula, you attempted to use SELECTEDVALUE to retrieve the value of 'PrimaryB_Individual' from the 'App Role' table. However, this usage of SELECTEDVALUE is problematic because it doesn't have a clear context for which 'App Role' row it should be considering. Additionally, your original formula didn't properly integrate the conditions from both the 'App' and 'App Role' tables.

The formula I provided in my previous response addresses these issues by using SUMX and FILTER functions to filter and count rows in the 'App Role' table based on the specified conditions from both tables. This ensures that the formula correctly links the two tables and returns the desired result based on the combined conditions.

I hope I was clear, BBF

Hi @BeaBF 

 

The formula works for all TRUE TRUE TRUE cases and False False False cases. I get an error when there is TRUE && TRUE && FALSE = FALSE(But I get TRUE). 

 

For example:  

 

Level 1 =
IF(
'App'[TBUS] <= 24 &&  (TRUE)
'App'[NE] = "Existing",  (TRUE
IF(
SUMX(FILTER('App Role', 'App Role'[Role] = "PB"(TRUE) && 'App Role'[App Type] = "Individual")(FALSE), 1) > 0,
1,
0
),
0
)

 

The result should be 0 but I get 1. Any ideas?

@Khushboo9966 Hi!

Try with:

Level 1 =
IF(
NOT ISEMPTY('App') &&
'App'[TBUS] <= 24 &&
'App'[NE] = "Existing",
IF(
CALCULATE(SUMX('App Role', 'App Role'[Role] = "PB" && 'App Role'[App Type] = "Individual")) > 0,
1,
0
),
0
)

BBF

@BeaBF : Error: SUMX cannot work with type Boolean

@Khushboo9966 
Level 1 =
IF(
NOT ISEMPTY('App') &&
'App'[TBUS] <= 24 &&
'App'[NE] = "Existing",
IF(
COUNTROWS(FILTER('App Role', 'App Role'[Role] = "PB" && 'App Role'[App Type] = "Individual")) > 0,
1,
0
),
0
)

BBF

@BeaBF The formula works but issue with False case.  

@Khushboo9966  could you provide more information?

 

BBF

@BeaBF 

 

Level 1 =
IF(
'App'[TBUS] <= 24 &&  (TRUE)
'App'[NE] = "Existing",  (TRUE
IF(
COUNTROWS(FILTER('App Role', 'App Role'[Role] = "PB" (TRUE) && 'App Role'[App Type] = "Individual")) (FALSE)> 0
1,
0
),
0
)

 

The result should be 0 but I get 1.

I am not sure if Countrows would work in this siutation because, the App Role has duplicate Application IDS(Primary Key joined with Application Table(Application ID)).

For example Application Role Table: 

Application IDApp TypeRole
1234Individualgc
1234OrgGC
1234OrgPB
1234IndividualGC

 

So the formula should return false because  App type = Indivdiual (True) but the corresponding value of App type = "Individual" is False. 

I hope this makes sense. 

@Khushboo9966 Try with:
=
IF(
AND('App'[TBUS] <= 24, 'App'[NE] = "Existing"),
IF(
SUMX(
FILTER('App Role',
'App Role'[Role] = "PB" && 'App Role'[App Type] = "Individual"
),
1
) > 0,
1,
0
),
0
)

 

BBF

@BeaBF 

 

I have the sample data attached here 

Hi, I have attached a sample PBIX file, Refer to App ID 914, The result of Level 1 should be 0 but I get 1. 

https://github.com/khushs9966/SampleAnalysis/blob/main/test.pbix 

Helpful resources

Announcements
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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