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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
PrasannaJ
Frequent Visitor

Assign value from one Column in a row to another column in other rows based on a condition

Hi,

I need help in the following:

I have a table like below

SiteURLTraffic
Aurl17
Aurl23
Burl39
Aurl46
Burl50

 

I want to add a 'Preferred URL' column, that provides a possible better URL based on `Traffic` within the `Site`, like below:

 

SiteURLTrafficPreferred URL
Aurl17url1
Aurl23url1
Burl39url3
Aurl46url1
Burl52url3

 

The logic is, within the site, the URL that gets max traffic is treated as the preferred URL for other URLs within the site.

For example, Site 'A' url1 has max traffic = 7, hence it becomes prefer url for Site A url2 & Site A url4. Similarly, Site B url3 becomes the preferred URL for Site B url 5.

Thanks.

1 ACCEPTED SOLUTION
kegoosse
Helper I
Helper I

@PrasannaJ 

This DAX might work if the Traffic values per site are unique

 

Highest traffic per site =
VAR MaxTraffic = CALCULATE(
    MAX(Table[Traffic]),
    FILTER(
        Table,
        Table[Site] = EARLIER(Table[Site])
    )
)
RETURN
CALCULATE(
    FIRSTNONBLANK(Table[URL],TRUE()),
    FILTER(
        Table,
        Table[Site] = EARLIER(Table[Site])
        &&
        Table[Traffic] = MaxTraffic
    )
)

 

 

If Traffic values per site can be repeated, you'll have to add a helper column which converts the traffic values to unique values (for example by adding and index multiplied by 0,000001). Then replace Table[Traffic] with Table[Helper column].

View solution in original post

2 REPLIES 2
PrasannaJ
Frequent Visitor

Awesome. Thanks @kegoosse . I made a small change based on your input as follows:

Highest traffic per site =
VAR MaxTraffic =
    CALCULATE(
        MAX('Table'[Traffic]),
        ALLEXCEPT('Table','Table'[Site])
        )
RETURN
    CALCULATE(
        FIRSTNONBLANK('Table'[Traffic],TRUE()),
        FILTER('Table','Table'[Site]=EARLIER('Table'[Site]) && 'Table'[Traffic]=MaxTraffic )
        )
kegoosse
Helper I
Helper I

@PrasannaJ 

This DAX might work if the Traffic values per site are unique

 

Highest traffic per site =
VAR MaxTraffic = CALCULATE(
    MAX(Table[Traffic]),
    FILTER(
        Table,
        Table[Site] = EARLIER(Table[Site])
    )
)
RETURN
CALCULATE(
    FIRSTNONBLANK(Table[URL],TRUE()),
    FILTER(
        Table,
        Table[Site] = EARLIER(Table[Site])
        &&
        Table[Traffic] = MaxTraffic
    )
)

 

 

If Traffic values per site can be repeated, you'll have to add a helper column which converts the traffic values to unique values (for example by adding and index multiplied by 0,000001). Then replace Table[Traffic] with Table[Helper column].

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.