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

DAX Calculation : CountX and SUMX

Hi All 

 

I am attaching a sample screenshot for the task that I am trying to achieve in power bi 

The image has both the input and expected output type

 

Please look and let me know if anyone can helpPowerbi community error.PNG

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

Total =
SWITCH (
    MAX ( 'Table (2)'[Category] ),
    "Count A", COUNT ( 'Table'[Col A] ),
    "Sum B", SUM ( 'Table'[Col B] )
)
Previous Month =
SWITCH (
    MAX ( 'Table (2)'[Category] ),
    "Count A",
        CALCULATE (
            COUNT ( 'Table'[Col A] ),
            FILTER ( 'Table', DATEDIFF ( 'Table'[DATE], TODAY (), MONTH ) = 0 )
        ),
    "Sum B",
        CALCULATE (
            SUM ( 'Table'[Col B] ),
            FILTER ( 'Table', DATEDIFF ( 'Table'[DATE], TODAY (), MONTH ) = 0 )
        )
)

9.png

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @Anonymous ,

 

Total =
SWITCH (
    MAX ( 'Table (2)'[Category] ),
    "Count A", COUNT ( 'Table'[Col A] ),
    "Sum B", SUM ( 'Table'[Col B] )
)
Previous Month =
SWITCH (
    MAX ( 'Table (2)'[Category] ),
    "Count A",
        CALCULATE (
            COUNT ( 'Table'[Col A] ),
            FILTER ( 'Table', DATEDIFF ( 'Table'[DATE], TODAY (), MONTH ) = 0 )
        ),
    "Sum B",
        CALCULATE (
            SUM ( 'Table'[Col B] ),
            FILTER ( 'Table', DATEDIFF ( 'Table'[DATE], TODAY (), MONTH ) = 0 )
        )
)

9.png

 

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Thanks Stephen 

amitchandak
Super User
Super User

@Anonymous , have tried time intelligence with date table

 

 

example

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

diff = [MTD Sales]-[last MTD Sales]

 

Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.