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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

filtering Top N with Calculate

I have created a VAR of top N table of customers and, got one column of the desired customers,

however, when I try to calculate a sum of sales (which is called [QoQ Variance]), using an "IN" statement it won't work.

 
 

 

top20Customer =
VAR topNTable =
    TOPN (
        20,
        SUMMARIZE ( 'Dataset', 'Dataset'[CustomerID] ),
        CALCULATE (
            SUM ( 'Dataset'[QoQ Variance] ),
            DATESBETWEEN (
                'Dataset'[Current Period],
                DATE ( 2019, 02, 01 ),
                DATE ( 2021, 01, 01 )
            ),
            MONTH ( 'Dataset'[Current Period] ) IN { 3, 6, 9, 12 },
            'Dataset'[RetentionCategory] = "Increase"
        )
    )
RETURN
    CALCULATE (
        SUM ( 'Dataset'[QoQ Variance] ),
        'Dataset'[CustomerID] IN topNTable
    )

 

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

Maybe:

 

RETURN
    CALCULATE (
        SUM ( 'Dataset'[QoQ Variance] ),
       INTERSECT( VALUES( 'Dataset'[CustomerID]), topNTable
    ))

or directly

RETURN
    CALCULATE (
        SUM ( 'Dataset'[QoQ Variance] ),
        topNTable
    )

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

1 REPLY 1
PaulDBrown
Community Champion
Community Champion

Maybe:

 

RETURN
    CALCULATE (
        SUM ( 'Dataset'[QoQ Variance] ),
       INTERSECT( VALUES( 'Dataset'[CustomerID]), topNTable
    ))

or directly

RETURN
    CALCULATE (
        SUM ( 'Dataset'[QoQ Variance] ),
        topNTable
    )

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.