Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago
Solved

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 c...
  • Anonymous's avatar
    Anonymous
    5 years ago

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

     

    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.