Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
431 views
in Technique[技术] by (71.8m points)

powerbi - Subtotal <> sum of the rows

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
        )
    )

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to MLink Developer Q&A Community for programmer and developer-Open, Learning and Share
...