Peter Hui
Peter Hui

Reputation: 119

Power BI Total Doesn't add up

I have a data model here.

data model

I added in a measure -

Test_SelectedValue =
CALCULATE (
    COUNTROWS ( Fact_Test ),
    FILTER (
        Fact_Test,
        Fact_Test[Sold]
            <= PERCENTILE.INC ( Fact_Test[Sold], SELECTEDVALUE (Threshold[Threshold]) )
    )
)

After nothing adds up. (image below) I want the measure to change with the selectedvalue dynamically

enter image description here

Upvotes: 0

Views: 97

Answers (1)

Alexis Olson
Alexis Olson

Reputation: 40204

This is because the threshold is being calculated separately for each row in your visual. I don't think that's what you're after. Try something like this instead:

Test_SelectedValue =
VAR Thresh =
    CALCULATE (
        PERCENTILE.INC ( Fact_Test[Sold], SELECTEDVALUE ( Threshold[Threshold] ) ),
        ALLSELECTED ()
    )
RETURN
    CALCULATE (
        COUNTROWS ( Fact_Test ),
        FILTER ( Fact_Test, Fact_Test[Sold] <= Thresh )
    )

This should remove the local filter context of date and region when calculating the threshold so that each row in your table is using the same population to calculate the percentile.

Upvotes: 1

Related Questions