You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Power BI中如何按指定规则生成最高浏览量屏幕名称新列?

Create Calculated Column for Top Screen Name in Power BI

Got it, let's build this calculated column step by step to meet your exact requirements. Here's how you can do it with DAX:

DAX Formula

Top Screen Name = 
VAR CurrentID = [id]
VAR CurrentStartDate = [start date]
VAR TodayFilter = TODAY()
-- Define the filtered group: today's data, same id+start date, and customer count = 1
VAR TargetGroup = 
    CALCULATETABLE(
        'YourTableName', -- Replace with your actual table name
        'YourTableName'[date] = TodayFilter,
        'YourTableName'[id] = CurrentID,
        'YourTableName'[start date] = CurrentStartDate,
        'YourTableName'[Customer Count] = 1 -- Replace with your customer count column name
    )
-- Get the maximum screen view count in the target group
VAR MaxViews = MAXX(TargetGroup, 'YourTableName'[Screen View Count]) -- Replace with your view count column name
-- Fetch the first screen name with the max view count (handles ties by picking the first one)
VAR TopScreen = 
    SELECTCOLUMNS(
        TOPN(
            1, 
            TargetGroup, 
            'YourTableName'[Screen View Count], DESC, -- Sort by view count descending
            'YourTableName'[Screen Name], ASC -- Break ties by screen name ascending (adjust if you want original order)
        ),
        "ScreenName", 'YourTableName'[Screen Name]
    )
-- Return the result, or blank if no matching data
RETURN
    IF(ISBLANK(MaxViews), BLANK(), TopScreen)

Key Explanations

  • Variables: We use variables to break down the logic for readability. CurrentID and CurrentStartDate anchor us to the current row's group.
  • Filtered Group: CALCULATETABLE narrows down the data to today's records, matching the current id/start date, and where the customer count equals 1.
  • Max View Count: MAXX grabs the highest screen view count from the filtered group.
  • Handle Ties: TOPN(1) ensures we pick the first screen name when multiple entries have the same max view count. The second sort parameter (Screen Name ASC) defines how ties are broken—if you prefer to use the original row order instead, you can add an index column to your table and sort by that instead.
  • Fallback: The final IF returns blank if there's no matching data for the group, avoiding errors.

Notes

  • Don't forget to replace placeholders like 'YourTableName', [Screen View Count], and [Customer Count] with your actual table and column names.
  • If your "customer count" is a calculated measure instead of a column, adjust the CALCULATETABLE filter to use FILTER(TargetGroup, CALCULATE([Customer Count Measure]) = 1) instead.

内容的提问来源于stack exchange,提问作者KARTHIKEYAN.A

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 08:32:32