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
bullius
Helper V
Helper V

New table with prioritised results in column

Hi

 

I would like a table SUMMARIZED by Employee ID, showing their main country of operation.

 

My data looks something like this:

 

Employee IDCountry
1UK
1France
2UK
2Spain
3UK
4Germany
5Brazil

 

I want a table that SUMMARIZES this by Employee ID and shows one country per Employee ID, prioritising non-UK countries for those that have more than one country of operation.

 

E.g.

 

Employee IDCountry
1France
2Spain
3UK
4Germany
5Brazil

 

Any ideas about how I might do this?

 

Thanks!

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

@bullius

 

Hi, A way to solve this:

 

In Original Table:

 

Create 3 columns:

 

isUK =
COUNTROWS (
    FILTER (
        Table1,
        Table1[Country] = "UK"
            && Table1[Employee ID] = EARLIER ( Table1[Employee ID] )
    )
)
TotalRows =
COUNTROWS (
    FILTER ( Table1, Table1[Employee ID] = EARLIER ( Table1[Employee ID] ) )
)
inNew =
IF (
    Table1[isUK] = 1
        && Table1[TotalRows] = 2
        && Table1[Country] = "UK";
    "No";
    "Yes"
)

or Just 1 Column:

 

InNew =
VAR isUK =
    COUNTROWS (
        FILTER (
            Table1,
            Table1[Country] = "UK"
                && Table1[Employee ID] = EARLIER ( Table1[Employee ID] )
        )
    )
VAR TotalRows =
    COUNTROWS (
        FILTER ( Table1, Table1[Employee ID] = EARLIER ( Table1[Employee ID] ) )
    )
RETURN
    IF (
        Table1[isUK] = 1
            && Table1[TotalRows] = 2
            && Table1[Country] = "UK",
        "No",
        "Yes"
    )

 

And A new Summarized Table:

 

Table =
SUMMARIZE (
    FILTER ( Table1; Table1[inNew] = "Yes" ),
    Table1[Employee ID],
    Table1[Country]
)



Lima - Peru

View solution in original post

1 REPLY 1
Vvelarde
Community Champion
Community Champion

@bullius

 

Hi, A way to solve this:

 

In Original Table:

 

Create 3 columns:

 

isUK =
COUNTROWS (
    FILTER (
        Table1,
        Table1[Country] = "UK"
            && Table1[Employee ID] = EARLIER ( Table1[Employee ID] )
    )
)
TotalRows =
COUNTROWS (
    FILTER ( Table1, Table1[Employee ID] = EARLIER ( Table1[Employee ID] ) )
)
inNew =
IF (
    Table1[isUK] = 1
        && Table1[TotalRows] = 2
        && Table1[Country] = "UK";
    "No";
    "Yes"
)

or Just 1 Column:

 

InNew =
VAR isUK =
    COUNTROWS (
        FILTER (
            Table1,
            Table1[Country] = "UK"
                && Table1[Employee ID] = EARLIER ( Table1[Employee ID] )
        )
    )
VAR TotalRows =
    COUNTROWS (
        FILTER ( Table1, Table1[Employee ID] = EARLIER ( Table1[Employee ID] ) )
    )
RETURN
    IF (
        Table1[isUK] = 1
            && Table1[TotalRows] = 2
            && Table1[Country] = "UK",
        "No",
        "Yes"
    )

 

And A new Summarized Table:

 

Table =
SUMMARIZE (
    FILTER ( Table1; Table1[inNew] = "Yes" ),
    Table1[Employee ID],
    Table1[Country]
)



Lima - Peru

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.