求助贴: TABLE 类型图表特定切片器下 RANKX 关于聚合指标的排序问题

Power Pivot 黯未来 ⋅ 于 2024-06-13 17:38:57 ⋅ 370 阅读

基本报表样式
file
问题描述

  1. 图表类型是 Table, 有3个切片器 Protocol ID、Site、Period 筛选数据
  2. 切片器 Protocol ID 和 Site 筛选确定 Chart显示的第一列 Subject。
    chart显示的第二列 [ECG DataUpload] 是一个度量值,第三列 [ECG DataUpload Format] 也是一个度量值,将ECG DataUpload 进行格式化。DAX表达式如下:
    ECG DataUpload = 
    VAR SelectedTenant = SELECTEDVALUE('TenantInformation'[Tenant])
    VAR SelectedSites = VALUES('Relation_SiteTenant'[Site])
    VAR SelectedPeriod = SELECTEDVALUE('Filter_PeriodTenant'[StatisticPeriod])
    VAR StartDate = LOOKUPVALUE('Filter_PeriodTenant'[PeriodStart], 'Filter_PeriodTenant'[Tenant], SelectedTenant, 'Filter_PeriodTenant'[StatisticPeriod], SelectedPeriod)
    VAR EndDate = LOOKUPVALUE('Filter_PeriodTenant'[PeriodEnd], 'Filter_PeriodTenant'[Tenant], SelectedTenant, 'Filter_PeriodTenant'[StatisticPeriod], SelectedPeriod)
    VAR TempTable = ADDCOLUMNS(
        VALUES('Relation_SubjectSite'[Subject]),
        "ECGDataUpload", CALCULATE(
            SUM('DataUpload_Device_Subject-df'[amount]),
            FILTER('DataUpload_Device_Subject-df',
                'DataUpload_Device_Subject-df'[Tenant] = SelectedTenant && 'DataUpload_Device_Subject-df'[Site] IN SelectedSites &&
                'DataUpload_Device_Subject-df'[Subject] = EARLIER('Relation_SubjectSite'[Subject]) &&
                'DataUpload_Device_Subject-df'[StatisticDate] >= StartDate && 'DataUpload_Device_Subject-df'[StatisticDate] <= EndDate
            )
        )
    )
    RETURN
    SUMX(TempTable, IF(ISBLANK([ECGDataUpload]), 0, [ECGDataUpload]))
    ECG DataUpload Format = 
    VAR SelectedTenant = SELECTEDVALUE('TenantInformation'[Tenant])
    VAR SelectedSites = VALUES('Relation_SiteTenant'[Site])
    VAR SelectedPeriod = SELECTEDVALUE('Filter_PeriodTenant'[StatisticPeriod])
    VAR StartDate = LOOKUPVALUE('Filter_PeriodTenant'[PeriodStart], 'Filter_PeriodTenant'[Tenant], SelectedTenant, 'Filter_PeriodTenant'[StatisticPeriod], SelectedPeriod)
    VAR EndDate = LOOKUPVALUE('Filter_PeriodTenant'[PeriodEnd], 'Filter_PeriodTenant'[Tenant], SelectedTenant, 'Filter_PeriodTenant'[StatisticPeriod], SelectedPeriod)
    VAR TempTable = ADDCOLUMNS(
        SUMMARIZE('Relation_SubjectSite',
            'Relation_SubjectSite'[Subject],
            "ECGDataUpload", CALCULATE(
                SUM('DataUpload_Device_Subject-df'[amount]),
                FILTER('DataUpload_Device_Subject-df',
                    'DataUpload_Device_Subject-df'[Tenant] = SelectedTenant && 'DataUpload_Device_Subject-df'[Site] IN SelectedSites &&
                    'DataUpload_Device_Subject-df'[StatisticDate] >= StartDate && 'DataUpload_Device_Subject-df'[StatisticDate] <= EndDate
                )
            )
        ),
        "TotalMinutes", IF(ISBLANK([ECGDataUpload]), 0, [ECGDataUpload]),
        "Days", INT(IF(ISBLANK([ECGDataUpload]), 0, [ECGDataUpload]) / 1440),
        "Hours", INT(MOD(IF(ISBLANK([ECGDataUpload]), 0, [ECGDataUpload]), 1440) / 60),
        "Minutes", MOD(IF(ISBLANK([ECGDataUpload]), 0, [ECGDataUpload]), 60)
    )
    RETURN
    MAXX(TempTable, [Days] & " days " & [Hours] & " hours " & [Minutes] & " minutes")
  3. Chart显示第四列Rank也需要创建1个度量值,显示第一列Subject按照第二列度量值[ECG DataUpload]排名后的值。
    但是,我目前创建的Rank表达式存在问题。要么是结果不正确,都是1. 要么是图表引入Rank后导致切片器 Protocol ID 和 Site的筛选失去作用,出现不符合筛选范围的Subject。
    错误Rank示例
    Rank = 
    VAR SelectedTenant = SELECTEDVALUE('TenantInformation'[Tenant])
    VAR SelectedSites = VALUES('Relation_SiteTenant'[Site])
    VAR SelectedPeriod = SELECTEDVALUE('Filter_PeriodTenant'[StatisticPeriod])
    VAR StartDate = LOOKUPVALUE('Filter_PeriodTenant'[PeriodStart], 'Filter_PeriodTenant'[Tenant], SelectedTenant, 'Filter_PeriodTenant'[StatisticPeriod], SelectedPeriod)
    VAR EndDate = LOOKUPVALUE('Filter_PeriodTenant'[PeriodEnd], 'Filter_PeriodTenant'[Tenant], SelectedTenant, 'Filter_PeriodTenant'[StatisticPeriod], SelectedPeriod)
    VAR TempTable = ADDCOLUMNS(
        SUMMARIZE('Relation_SubjectSite', 'Relation_SubjectSite'[Subject],
            "ECGDataUpload", CALCULATE(
                SUM('DataUpload_Device_Subject-df'[amount]),
                FILTER('DataUpload_Device_Subject-df',
                    'DataUpload_Device_Subject-df'[Tenant] = SelectedTenant && 'DataUpload_Device_Subject-df'[Site] IN SelectedSites &&
                    'DataUpload_Device_Subject-df'[StatisticDate] >= StartDate && 'DataUpload_Device_Subject-df'[StatisticDate] <= EndDate
                )
            )
        ),
        "TotalMinutes", IF(ISBLANK([ECGDataUpload]), 0, [ECGDataUpload])
    )
    RETURN
    IF(ISBLANK([ECG DataUpload]),BLANK(),RANKX(TempTable,MAXX(TempTable, [TotalMinutes]),,DESC,DENSE))
    Rank = 
    VAR SelectedTenant = SELECTEDVALUE('TenantInformation'[Tenant])
    VAR SelectedSites = VALUES('Relation_SiteTenant'[Site])
    VAR SelectedPeriod = SELECTEDVALUE('Filter_PeriodTenant'[StatisticPeriod])
    VAR StartDate = LOOKUPVALUE('Filter_PeriodTenant'[PeriodStart], 'Filter_PeriodTenant'[Tenant], SelectedTenant, 'Filter_PeriodTenant'[StatisticPeriod], SelectedPeriod)
    VAR EndDate = LOOKUPVALUE('Filter_PeriodTenant'[PeriodEnd], 'Filter_PeriodTenant'[Tenant], SelectedTenant, 'Filter_PeriodTenant'[StatisticPeriod], SelectedPeriod)
    VAR TempTable = ADDCOLUMNS(
        SUMMARIZE(
            'Relation_SubjectSite',
            'Relation_SubjectSite'[Subject]
        ),
        "ECGDataUpload", CALCULATE(
            SUM('DataUpload_Device_Subject-df'[amount]),
            'DataUpload_Device_Subject-df'[Tenant] = SelectedTenant && 'DataUpload_Device_Subject-df'[Site] IN SelectedSites &&
            'DataUpload_Device_Subject-df'[StatisticDate] >= StartDate && 'DataUpload_Device_Subject-df'[StatisticDate] <= EndDate
        )
    )
    VAR CurrentECGDataUpload = CALCULATE(
        SUM('DataUpload_Device_Subject-df'[amount]),
        'DataUpload_Device_Subject-df'[Tenant] = SelectedTenant && 'DataUpload_Device_Subject-df'[Site] IN SelectedSites &&
        'DataUpload_Device_Subject-df'[Subject] = SELECTEDVALUE('Relation_SubjectSite'[Subject]) &&
        'DataUpload_Device_Subject-df'[StatisticDate] >= StartDate && 'DataUpload_Device_Subject-df'[StatisticDate] <= EndDate
    )    
    RETURN
    IF(
    ISBLANK(CurrentECGDataUpload),
    BLANK(),
    RANKX(
        TempTable,
        [ECGDataUpload],
        CurrentECGDataUpload,
        DESC,
        DENSE
    )
    )

    以上2个Rank,计算结果都有问题。Subject对应的值都是1。
    求助内容
    这种情景下,Rank这个度量值如何创建?实现下面的排名效果?
    file

仗义每多屠狗辈!

回复数量: 0
    暂无评论~~
    • 请务必阅读并严格遵守《社区管理规范与使用说明》
    • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`, 更多语法请见这里 Markdown 语法
    • 支持表情,使用方法请见 发送表情,可用的 Emoji 见 :metal: :point_right: Emoji 列表 :star: :sparkles:
    • 上传图片, 支持拖拽和剪切板粘贴上传, 格式限制 - jpg, png, gif
    • 不支持上传附件,请尽可能用文字和图片将问题描述清楚,如实在需要上传附件,可上传到 共享网盘 后分享链接
    • 发布框支持本地存储功能,会在内容变更时保存,「提交」按钮点击时清空
      请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
    Ctrl+Enter