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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
romoguy15
Helper IV
Helper IV

Group Column of locations based on condition from another column

Hi,

 

I have been working to try and come up with a calculated column that can tell me if my list of locations meets a specific condition with a Yes/No statement.

 

I have a list of locatins with a column of different tickets. The locations are listed more than once but can have two different types of tickets. I am trying to group the locations to say if Location has a PSU and a Non NWR Ticket, "Yes", if not then "No". The calculation column it tried using below as well as several other attempts but it seems i'm not fully understanding how to achieve it.

 
 = CALCULATE(IF(FILTER(ALL('Sample'[Location], 'Sample'[Ticket]), 'Sample'[Ticket] = "PSU" && "Non NWR"), "Yes", "No"))

 

Below is the sample data

https://1drv.ms/u/s!AqID1H0nHPOzhAoeXiSYdvCbmb-e?e=4iU40P

 

Attached is an example snip from excel of what I am getting at

romoguy15_0-1618432157101.png

I appreciate the support and any input I can get.

 

Thank you

2 ACCEPTED SOLUTIONS
mahoneypat
Employee
Employee

Here is a column expression that shows one way to do it.

 

Has Both =
VAR vResult =
    CALCULATE (
        DISTINCTCOUNT ( 'Sample'[Ticket] ),
        ALLEXCEPT ( 'Sample', 'Sample'[Location] ),
        'Sample'[Ticket] IN { "PSU""Non NWR" }
    )
RETURN
    IF ( vResult = 2"Y""N" )

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

Anonymous
Not applicable

Here's a faster version that does not rely on CALCULATE:

 

// T is the name of your table.

[Your Column] = // calculated column
var CurrentLocation = T[Location]
var TicketTable = {"psu", "non nwr"}
var Yes =
    2 = COUNTROWS(
        filter(
            ALL( T[Location], T[Ticket] ),
            T[Location] = CurrentLocation
            &&
            T[Ticket] in TicketTable
        )
    )
return
    if( Yes, "Yes", "No" )

View solution in original post

3 REPLIES 3
romoguy15
Helper IV
Helper IV

@mahoneypat & @Anonymous  thank you both for the solution. Not that I would have figured out the entire equation but I did not stop to think of using VAR. Thank you.

mahoneypat
Employee
Employee

Here is a column expression that shows one way to do it.

 

Has Both =
VAR vResult =
    CALCULATE (
        DISTINCTCOUNT ( 'Sample'[Ticket] ),
        ALLEXCEPT ( 'Sample', 'Sample'[Location] ),
        'Sample'[Ticket] IN { "PSU""Non NWR" }
    )
RETURN
    IF ( vResult = 2"Y""N" )

 

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Anonymous
Not applicable

Here's a faster version that does not rely on CALCULATE:

 

// T is the name of your table.

[Your Column] = // calculated column
var CurrentLocation = T[Location]
var TicketTable = {"psu", "non nwr"}
var Yes =
    2 = COUNTROWS(
        filter(
            ALL( T[Location], T[Ticket] ),
            T[Location] = CurrentLocation
            &&
            T[Ticket] in TicketTable
        )
    )
return
    if( Yes, "Yes", "No" )

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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