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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
audstrich
Regular Visitor

DAX help

Hi everyone,

 

I would like to get one of three outputs from the expression that I am hoping someone can teach me about: trial, implant, or battery replacement. Two of these outputs are very simple, one code relates to each. But the "implant" output will need to see if both codes were used under the same ID number.

 

63650 alone = trial

63685 alone = battery replacement

63650 & 63685 = implant

 

ID NumberCodeOutput
163650trial
263685battery replacement
363650implant
363685implant

 

The data has only one code per row and each row has an ID number. The column should return "implant" if there are two rows with the same ID number, one containing the code 63650 and the other containing 63685.

 

There are other codes used in the table but I only care about an output for these three instances.

 

Thank you!! I'm sure this isn't very complicated but I'm no expert and I very much so appreciate the help.

 

Audrey

 

 

 

 

1 ACCEPTED SOLUTION

@audstrich add new column in your table using following expression

 

Output 2 = 
VAR __data = CALCULATETABLE( VALUES(Table8[Code]), ALLEXCEPT( Table8, Table8[ID Number] ) )
RETURN
IF( Table8[Code] IN {"63650","63685" },
    SWITCH( TRUE(),
        "63650" IN __data  &&  NOT "63685"  IN __data , "Trial",
        "63685" IN __data  &&  NOT "63650"  IN __data , "Battery Replacement",
        "63685" IN __data  &&      "63650"  IN __data , "Implant"
    )
)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

11 REPLIES 11
parry2k
Super User
Super User

@audstrich your question is not fully clear, what is the logic to get output "Trial" or "battery replacement" , although is clear if there is more than one code under same id then it will be "Implant" but not sure what is the logic in first two cases?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k trial or battery replacement is used when for that ID number there is only the one code, or the only other instances for that ID are other codes not included in the table (99124, J1100, etc.). If there is only 63650 for that ID and no 63685 as well for that ID, then it is a trial. If only 63685 and no 63650 for that ID, it was a battery replacement. The ID number is the unique value assigned to a procedure that could include many codes or just one.

 

I'm sure there is a much shorter version to explain this in logical terms, I'm sorry!

 

 

@audstrich add new column in your table using following expression

 

Output 2 = 
VAR __data = CALCULATETABLE( VALUES(Table8[Code]), ALLEXCEPT( Table8, Table8[ID Number] ) )
RETURN
IF( Table8[Code] IN {"63650","63685" },
    SWITCH( TRUE(),
        "63650" IN __data  &&  NOT "63685"  IN __data , "Trial",
        "63685" IN __data  &&  NOT "63650"  IN __data , "Battery Replacement",
        "63685" IN __data  &&      "63650"  IN __data , "Implant"
    )
)


Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Capture.PNG

A single value for column 'CPT Code' in table 'Master 37105' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

Are you adding a measure or column?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Column.

Hmmm, not sure why it will give an error message when it is column, can you test it on sample dataset you provided, it all worked fine for me

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

The Home Table was wrong! It works beautifully now. Thank you so much!! I really appreciate it.

Woo hoo, glad to hear.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thank you so much! But it's still not working. I get this error:

 

A single value for column 'Code' in table 'Table 8' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

 

When I add COUNT to the formula, I get this error:

 

Function 'CONTAINSROW' does not support comparing values of type Text with values of type Integer. Consider using the VALUE or FORMAT function to convert one of the values.

@audstrich I'm not sure what you mean by count in the formula, first add this column and then you can add measure to count different output.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors