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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

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"
)

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"
)

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

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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