首页 文章

计算DAX中的PERCENTILE

提问于
浏览
0

我用谷歌搜索并继续使用太慢的公式 . 我怀疑如果我按步骤分割公式(创建计算列),我可能会看到一些性能提升 .

我有一个表有一些数字列和一些最终将作为切片 . 目的是在所选切片器的某些数字列上具有10%,25%,50%,75%和90%的百分位数 .

这就是我对“总钯”栏目中的第10个百分位数的看法 .

TotalPaid10thPercentile:=MINX(
                              FILTER(
                                     VALUES(ClaimOutcomes[Total Pd]),
                                     CALCULATE(
                                               COUNTROWS(ClaimOutcomes),
                                               ClaimOutcomes[Total Pd] <= EARLIER(ClaimOutcomes[Total Pd]) 
                                              )> COUNTROWS(ClaimOutcomes)*0.1
                                    ),
                               ClaimOutcomes[Total Pd]
                             )

这需要几分钟,但仍然没有数据显示 . 我在这张表中有大约300K的记录 .

1 回答

  • 1

    我找到了一种方法,可以通过一系列步骤打破计算,从而获得了一个非常快速的解决方案 .

    为了计算表 DataAmount Paid 的第10个百分位数,我遵循了下面的书外公式:

    Calculate the Ordinal rank for the 10th percentile element

    10ptOrdinalRank:=0.10*(COUNTX('Data', [Amount Paid]) - 1) + 1
    

    它可能会出现一个十进制(分数)数字,如112.45

    Compute the decimal part

    10ptDecPart:=[10ptOrdinalRank] - TRUNC([10ptOrdinalRank])
    

    Compute the ordinal rank of the element just below(floor)

    10ptFloorElementRank:=FLOOR([10ptOrdinalRank],1)
    

    Compute the ordinal rank of the element just above(ceiling)

    10ptCeilingElementRank:=CEILING([10ptOrdinalRank], 1)
    

    Compute element corresponding to floor

    10ptFloorElement:=MAXX(TOPN([10ptFloorElementRank], 'Data',[Amount Paid],1), [Amount Paid])
    

    Compute element corresponding to ceiling

    10ptCeilingElement:=MAXX(TOPN([10ptCeilingElementRank], 'Data',[Amount Paid],1), [Amount Paid])
    

    Compute the percentile value

    10thPercValue:=[10ptFloorElement] + [10ptDecPart]*([10ptCeilingElement]-[10ptFloorElement])
    

    我发现性能明显快于我在网上找到的其他解决方案 . 希望它能帮助将来的某个人 .

相关问题