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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Anonymous
Not applicable

Conditional Column based on multiple rows

I have one table that I need to add a conditional column or other solution I haven't considered. I need to know for each customer, if any of their contacts is subscribed to any of the subscriptions. So one yes for Customer AAA in those 3 rows of 3 subscription types would be "YES" and customer BBB would be "NO" because their two contacts is not signed up for any subscriptions.

 

Is there a conditional column or new/merged query or grouping I would use to get there?

 

I am creating a dashboard that will have a red or green icon beside each custoemer to tell me that at least one person at that customer is signed up for an alert/subscription.

 

Current State

Customer NameUserSubscription 1Subscription 2Subscription 3
AAAJenYesNoNo
AAAAmyNoNoNo
AAACarlNoYesNo
BBBMarkNoNoNo
BBBDonNoNoNo

 

Needed Result

Customer NameSubscription
AAAYes
BBBNo
1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @Anonymous 

 

Download this example PBIX file.

 

This measure does what you want.

 

Measure = IF(CALCULATE(COUNTROWS('Table'), FILTER('Table', 'Table'[Subscription 1] = "Yes" || 'Table'[Subscription 2] = "Yes" || 'Table'[Subscription 3] = "Yes")) > 0 , "Yes", "No")

 

subs.png

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

3 REPLIES 3
v-yiruan-msft
Community Support
Community Support

Hi @Anonymous ,

You can create a measure as below:

Subscription = 
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( 'Table'[User] ),
        FILTER (
            'Table',
            'Table'[Customer Name] = SELECTEDVALUE ( 'Table'[Customer Name] )
                && ( 'Table'[Subscription 1] = "Yes"
                || 'Table'[Subscription 2] = "Yes"
                || 'Table'[Subscription 3] = "Yes" )
        )
    )
RETURN
    IF ( _count > 0, "Yes", "No" )

yingyinr_0-1615790864221.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
PhilipTreacy
Super User
Super User

Hi @Anonymous 

 

Download this example PBIX file.

 

This measure does what you want.

 

Measure = IF(CALCULATE(COUNTROWS('Table'), FILTER('Table', 'Table'[Subscription 1] = "Yes" || 'Table'[Subscription 2] = "Yes" || 'Table'[Subscription 3] = "Yes")) > 0 , "Yes", "No")

 

subs.png

Regards

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi, if I may, I'm trying to do something similar, but I need to be able to store the output on my table. I tried using the same functions but instead of using a measure using a calculated column but it doesn't work (I believe calculated columns only evaluate row by row, right)

 

Would you have a suggestion on how to achieve something similar but to be able to save it on a table? I basically need to be able to a pie chart showing (trying to keep the same example as above) number of customer with and without subscriptions.

 

Thanks

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.