DAX percentiles of sums

隐身守侯 提交于 2019-12-12 04:56:22

问题


I have a table with the following fields:

[Date]
[Ref Nr]
[Units]

I'd like to do a SUM over [Units] for each value in [Date] and [Ref Nr] and then take a 80 percentile for each value in [Ref Nr].

I've tried the following but it doesn't work...

DEFINE

MEASURE 'Table'[Pctl] = 

CALCULATE(
    PERCENTILEX.INC(
        'Table',
        CALCULATE(
            SUM('Table'[Units]),
            ALLEXCEPT('Table',
                      'Table'[Date],
                      'Table'[Ref Nr]
            )
        ),
        0.8
    ),
    ALLEXCEPT('Table',
              'Table'[Ref Nr]
    )
)

EVALUATE


FILTER(
    SUMMARIZE(
        'Table',
        'Table'[Ref Nr],
        "Percentile 80",
        'Table'[Pctl]
    ),
    'Table'[Pctl] <> 0
)

Could you please guide me how to make it work?

Thanks in advance :)


回答1:


I think your Pct1 calculation should look as follows:

MEASURE 'Table'[Pctl] = 
CALCULATE(
    PERCENTILEX.INC(
        VALUES('Table'[Date],
        CALCULATE(SUM('Table'[Units])),
        0.8
    )
)

as it will be evaluated in the context of [Ref Nr] in the final query, VALUES('Table'[Date]) will only return dates for the current [Ref Nr], the rest of the calculation should be clear I think



来源:https://stackoverflow.com/questions/46071807/dax-percentiles-of-sums

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!