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
michaeljhenley0
New Member

Rolling up a list via the most common value in a column

Hello,

 

I am relatively new to Power BI. I'm trying to create a list that surveys a large table full of contact, geographic and policy info.

 

I have two tables. Table 1 starts with a text string of State-County-Policy # and then invidual locations with individual contact names and numbers. Often, there are repeats.

 

State/County/PolicyLocationContact NameContact Number
AK-ANCHORAGE-00011GUY SMITH9999999999
AK-ANCHORAGE-00012GUY SMITH9999999999
AK-ANCHORAGE-00013GUY SMITH9999999999
AK-ANCHORAGE-00014DAVID SMITH8888888888
AK-ANCHORAGE-00015DAVID SMITH8888888888
AK-ANCHORAGE-00016DAVID SMITH8888888888
AK-ANCHORAGE-00027PETER SMITH7777777777
AK-ANCHORAGE-00028PETER SMITH7777777777
AK-ANCHORAGE-00029PHIL SMITH6666666666
AK-ANCHORAGE-000310JOHN SMITH5555555555

 

Table 2 is a summarized version of this first table where I want to roll up table 1 into one State-County-Policy instance per line, with the contact name and contact number populated by the most common value that occured in each of those columns for that state-county-policy combination.

 

State/County/PolicyContact NameContact Number
AK-ANCHORAGE-0001  
AK-ANCHORAGE-0002  
AK-ANCHORAGE-0003  

 

So, in other words I would want table 2 to look like this, selecting the most common values from filtering table 1 via the state/county/policy.

 

State/County/PolicyContact NameContact Number
AK-ANCHORAGE-0001GUY SMITH9999999999
AK-ANCHORAGE-0002PETER SMITH7777777777
AK-ANCHORAGE-0003JOHN SMITH5555555555

 

Is this possible?

1 ACCEPTED SOLUTION
v-yiruan-msft
Community Support
Community Support

Hi @michaeljhenley0 ,

You can create a calculated table as below:

Table 2 = 
VAR _table =
    SUMMARIZE (
        'Table',
        'Table'[State/County/Policy],
        'Table'[Contact Name],
        'Table'[Contact Number],
        "countofcn", CALCULATE ( COUNT ( 'Table'[Contact Number] ) )
    )
VAR _table2 =
    ADDCOLUMNS (
        _table,
        "maxcount",
            MAXX (
                FILTER ( _table, [State/County/Policy] = EARLIER ( [State/County/Policy] ) ),
                [countofcn]
            )
    )
VAR _table3 =
    SUMMARIZE (
        FILTER ( _table2, [countofcn] = [maxcount] ),
        [State/County/Policy],
        [Contact Name],
        [Contact Number]
    )
RETURN
    _table3

yingyinr_1-1623740922615.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.

View solution in original post

1 REPLY 1
v-yiruan-msft
Community Support
Community Support

Hi @michaeljhenley0 ,

You can create a calculated table as below:

Table 2 = 
VAR _table =
    SUMMARIZE (
        'Table',
        'Table'[State/County/Policy],
        'Table'[Contact Name],
        'Table'[Contact Number],
        "countofcn", CALCULATE ( COUNT ( 'Table'[Contact Number] ) )
    )
VAR _table2 =
    ADDCOLUMNS (
        _table,
        "maxcount",
            MAXX (
                FILTER ( _table, [State/County/Policy] = EARLIER ( [State/County/Policy] ) ),
                [countofcn]
            )
    )
VAR _table3 =
    SUMMARIZE (
        FILTER ( _table2, [countofcn] = [maxcount] ),
        [State/County/Policy],
        [Contact Name],
        [Contact Number]
    )
RETURN
    _table3

yingyinr_1-1623740922615.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.

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.