The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi,
I need help in the following:
I have a table like below
Site | URL | Traffic |
A | url1 | 7 |
A | url2 | 3 |
B | url3 | 9 |
A | url4 | 6 |
B | url5 | 0 |
I want to add a 'Preferred URL' column, that provides a possible better URL based on `Traffic` within the `Site`, like below:
Site | URL | Traffic | Preferred URL |
A | url1 | 7 | url1 |
A | url2 | 3 | url1 |
B | url3 | 9 | url3 |
A | url4 | 6 | url1 |
B | url5 | 2 | url3 |
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.
Solved! Go to Solution.
@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].
Awesome. Thanks @kegoosse . I made a small change based on your input as follows:
@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].
User | Count |
---|---|
15 | |
13 | |
9 | |
6 | |
6 |
User | Count |
---|---|
27 | |
19 | |
13 | |
9 | |
5 |