Subtotal <> sum of the rows

做~自己de王妃 提交于 2021-01-28 11:17:40

问题


I'm a relative neophyte with DAX so bear with me. In the simplest terms, I want to double the measure amount for all regions that are not Europe, then sum the result. Here is some example DAX:

DEFINE
    
measure Fact[test] = CALCULATE (IF(SELECTEDVALUE('Dim'[Region]) = "Europe", Fact[Revenue],Fact[Revenue] * 2))

EVALUATE(
    SUMMARIZECOLUMNS(
        ROLLUPADDISSUBTOTAL('Dim'[Region], "RegionSubtotal"),
        "Original Measure", Fact[Revenue],
        "New Measure", Fact[test]
    )
)
Region RegionSubtotal Original Measure New Measure
Asia False 200 400
Americas False 500 1000
Europe False 300 300
True 1000 2000

I'm trying to get (400+1000+300) = 1700 for the second column instead of 2000. Any ideas?


回答1:


For the subtotal row, the selected value is not "Europe" so it's doubling the value.

To fix this, you want to iterate over the regions in your measure. Something like this:

test =
    SUMX (
        VALUES ( 'Dim'[Region] ),
        IF (
            'Dim'[Region] = "Europe",
            [Revenue],
            [Revenue] * 2
        )
    )



回答2:


An other alternative would be to create a calculated column wherein , in case if region<>Europe, then amount* 2 else amount. Then take the sum of the calculated column , but this would be like having an additional data .



来源:https://stackoverflow.com/questions/65515750/subtotal-sum-of-the-rows

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