Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
avanderschilden
Resolver I
Resolver I

Issue with SUMX in ISINSCOPE

Hello,

 

I have a measure that calculates reactivated users by date, and this produces the expected result.

However, I am not able to produce the sum of reactivated users for all days within the selected month.

 

When I manually add up all reactivated users for a month, it does not match with the result produced on monthly level by the measure. 

 

Does anyone have an idea why the monthly total is producing a different result from adding the daily numbers up manually?

 

Regards,

Adrian

 

Reactivated = 

VAR __CurrentUsers =
    CALCULATETABLE ( VALUES ( 'F Orders'[UserId] ), 'D Order'[IsCompleted] = "Yes" )

VAR __UsersLast180Days =
    CALCULATETABLE (
        VALUES ( 'F Orders'[UserId] ),
        FILTER (
            ALL ( 'D Calendar'[Date] ),
            'D Calendar'[Date]
                >= MIN ( 'D Calendar'[Date] ) - 180
                && 'D Calendar'[Date]
                    <= MIN ( 'D Calendar'[Date] ) - 1
        ),
        'D Order'[IsCompleted] = "Yes"
    )

VAR __UserBefore180Days =
    CALCULATETABLE (
        VALUES ( 'F Orders'[UserId] ),
        FILTER (
            ALL ( 'D Calendar'[Date] ),
            'D Calendar'[Date]
                < MIN ( 'D Calendar'[Date] ) - 180
        ),
        'D Order'[IsCompleted] = "Yes"
    )

VAR __Result =
    CALCULATE (
        DISTINCTCOUNT ( 'F Orders'[UserId] ),
        FILTER (
            ALL ( 'F Orders'[UserId] ),
            'F Orders'[UserId] IN __CurrentUsers
                && 'F Orders'[UserId] IN __UserBefore180Days
                && NOT 'F Orders'[UserId] IN __UsersLast180Days
        )
    )

RETURN
    IF (
        ISINSCOPE ( 'D Calendar'[Date] ),
        __Result,
        SUMX (
            VALUES ( 'D Calendar'[Date] ),
            CALCULATE (
                CALCULATE (
                    DISTINCTCOUNT ( 'F Orders'[UserId] ),
                    FILTER (
                        ALL ( 'F Orders'[UserId] ),
                        'F Orders'[UserId]
                            IN CALCULATETABLE ( VALUES ( 'F Orders'[UserId] ), 'D Order'[IsCompleted] = "Yes" )
                            && 'F Orders'[UserId]
                                IN CALCULATETABLE (
                                    VALUES ( 'F Orders'[UserId] ),
                                    FILTER (
                                        ALL ( 'D Calendar'[Date] ),
                                        'D Calendar'[Date]
                                            < MIN ( 'D Calendar'[Date] ) - 180
                                    ),
                                    'D Order'[IsCompleted] = "Yes"
                                )
                            && NOT 'F Orders'[UserId]
                                IN CALCULATETABLE (
                                    VALUES ( 'F Orders'[UserId] ),
                                    FILTER (
                                        ALL ( 'D Calendar'[Date] ),
                                        'D Calendar'[Date]
                                            >= MIN ( 'D Calendar'[Date] ) - 180
                                            && 'D Calendar'[Date]
                                                <= MIN ( 'D Calendar'[Date] ) - 1
                                    ),
                                    'D Order'[IsCompleted] = "Yes"
                                )
                    )
                )
            )
        )
    )
3 REPLIES 3
Anonymous
Not applicable

Messy code like hell... 😞 Very likely it can be significantly optimized and shortened.

But I don't think anyone's gonna help you unless you provide some sample data, the model structure and show what you expect and what the actual outcome is.

It would also be useful if you could tell in your own words what the code is actually supposed to do. For instance, why is there a different formula for when one date is in scope and for when there are more than 1? Can this not be unified into one?

Best
Darek

@Anonymous
Did you had time to look at the pbix by any chance?

Hi Darek,

 

I've created the model and a report page to explain the issue; https://we.tl/t-3M2uO84dhh

 

The measure "Reactivated Users" is calculating the number of unique users that places an order on a selected date, but not placed an order in the last 40 days, but did place an order before 40 days ago. Therefor, 3 sets are prepared in variables to find if a user is in two of those sets and not in the set of orders in the last 40 days. 

 

Basically I want the month total in the table to be equal to the manual sum of all days within the month. Somehow the measure is giving a result that is not equal to the total of all days.

 

Thanks in advance for your help!

 

Regards,

Adrian

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.