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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
flywheel_1987
New Member

How to group by IDs and show whether a product exists under the IDs and flag them

Hello,

 

I recently took over a colleagues work as he left. I am not a BI developer but I do have some experiences with PowerBI. I have this table:

Screenshot 2023-06-19 at 10.36.43 AM.png

 

 

 

 

 

 

 

 

 

 

A customer ID can have multiple products. I am trying to find Checking Only, Loan Only Customers, etc customer. I need to group by Account number. The whole thing is coming from an SSAS model so I can't create a conditional column in the PowerBI. I believe I have to use a variable table or some sort and summarize by ID and product type. 

This is what I want to show as I want to have flags so that I can create other measurements:


Screenshot 2023-06-19 at 10.37.29 AM.png

 

The logic I have created wouldn't work since I am looking as columns but they are coming as rows:

Here is a DAX measurement I have created (obviously it doesnt work):

 

Checking_Only Flag =

VAR CheckingAccts = CALCULATE(Count(Accounts [Accounts ID]), Products [Product Description] = "Checking")

VAR SavingsAccts = CALCULATE(Count(Accounts [Accounts ID]), Products [Product Description] = "Savings")

VAR LoansAccts = CALCULATE(Count(Accounts [Accounts ID]), Products [Product Description] = "Loan")

VAR TimeDepositAccts = CALCULATE (Count(Accounts [Accounts ID]), Products [Product Description] = "Time Deposit")

VAR MoneyMarketAccts = CALCULATE (Count(Accounts [Accounts ID]), Products[Product Description] = "Money Market")

VAR CreditCardAccts = CALCULATE(Count(Accounts [Accounts ID]), Products [Product Description] = "Credit Card")

VAR CustomerCount = CALCULATE(DISTINCTCOUNT (Customers [CustomerID]), CheckingAccts > 0, SavingsAccts = 0, TimeDepositAccts = 0,
MoneyMarketAccts = 0, CreditCardAccts = 0)

Return CustomerCount

 

The other way I wanted to do is:

Only Flag =

VAR CheckingAccts = CALCULATE(Count(Accounts [Accounts ID]), Products [Product Description] = "Checking")

VAR SavingsAccts = CALCULATE(Count(Accounts [Accounts ID]), Products [Product Description] = "Savings")

VAR LoansAccts = CALCULATE(Count(Accounts [Accounts ID]), Products [Product Description] = "Loan")

VAR TimeDepositAccts = CALCULATE (Count(Accounts [Accounts ID]), Products [Product Description] = "Time Deposit")

VAR MoneyMarketAccts = CALCULATE (Count(Accounts [Accounts ID]), Products[Product Description] = "Money Market")

VAR CreditCardAccts = CALCULATE(Count(Accounts [Accounts ID]), Products [Product Description] = "Credit Card")

VAR Logic =
IF(CheckingAccts > 0 && SavingsAccts = 0 && LoansAccts = 0 && TimeDepositAccts = 0 && CreditCardAccts = 0 && MoneyMarketAccts = 0, "Checking"

, IF(CheckingAccts = 0 && SavingsAccts > 0 && LoansAccts = 0 && TimeDepositAccts = 0 && CreditCardAccts = 0 && MoneyMarketAccts = 0, "Savings"

, IF(CheckingAccts = 0 && SavingsAccts = 0 && LoansAccts  > 0 && TimeDepositAccts = 0 && CreditCardAccts = 0 && MoneyMarketAccts = 0, “Loans”

, IF(CheckingAccts = 0 && SavingsAccts = 0 && LoansAccts = 0 && TimeDepositAccts > 0 && CreditCardAccts = 0 && MoneyMarketAccts = 0, “Time “Deposit

, IF(CheckingAccts = 0 && SavingsAccts = 0 && LoansAccts = 0 && TimeDepositAccts = 0 && CreditCardAccts > 0 && MoneyMarketAccts = 0, “Credit Cards”

, IF(CheckingAccts = 0 && SavingsAccts = 0 && LoansAccts = 0 && TimeDepositAccts = 0 && CreditCardAccts = 0 && MoneyMarketAccts = 0, "Savings”,

 “NA”)))))

 

RETURN Logic

 

I am assuming I have to utilize a function called addcolumn or addtable or something to create a variable table through measurement and use that for figuring out how many "Only" customers exists so that I can select or filter whichever only customer I want to look at.

 

Any help on this request will be extremely helpful. Thank you for reading this.

 

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@flywheel_1987 , you have to create a measure like the below, Add additional conditions

 

 

Measure =
Var _cnt = CALCULATE(COUNTROWS(Fact), allexcept(Fact, Fact[Customer id]))
Var _Checking_Only = CALCULATE(COUNTROWS(Fact), allexcept(Fact, Fact[Customer id]), Products[Product Description] = "Checking")
Var _Loan_Only = CALCULATE(COUNTROWS(Fact), allexcept(Fact, Fact[Customer id]), Products[Product Description] = "Loan")


Return
Switch( True() ,
_cnt = _Checking_Only && _Checking_Only >0 , "Only Checking",
_cnt = _Loan_Only && _Checking_Only >0 , "Only Load"
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

4 REPLIES 4
amitchandak
Super User
Super User

@flywheel_1987 , you have to create a measure like the below, Add additional conditions

 

 

Measure =
Var _cnt = CALCULATE(COUNTROWS(Fact), allexcept(Fact, Fact[Customer id]))
Var _Checking_Only = CALCULATE(COUNTROWS(Fact), allexcept(Fact, Fact[Customer id]), Products[Product Description] = "Checking")
Var _Loan_Only = CALCULATE(COUNTROWS(Fact), allexcept(Fact, Fact[Customer id]), Products[Product Description] = "Loan")


Return
Switch( True() ,
_cnt = _Checking_Only && _Checking_Only >0 , "Only Checking",
_cnt = _Loan_Only && _Checking_Only >0 , "Only Load"
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

This is awesome! Thank you very much. Do you know if there is a way to count these flags? I need get these numbers for another calculation and show them as card for each "Only Flags". 

@flywheel_1987 , one way is individual measures, another is segmentation

 

very similar to

Customer Retention with Dynamic Segmentation, New/Lost/Retain Customer Count: https://youtu.be/EyL7KMw877Q

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

This is exactly what I needed. Thank you so much for all your help.

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors