Forum Discussion

AleFVG's avatar
AleFVG
Icon for Helper I rankHelper I
5 years ago
Solved

Sum Groupby only for current year

Hello guys!   i have this dax formula:   ABC by Year = GROUPBY('Fact','Fact'[Supplier],"Spend",SUMX(CURRENTGROUP(),'Fact'[Spend]))     how can i change it because i only sum the values of th...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi AleFVG ,

    Here is my data sample and pbix file.

    2020-1-11
    2019-1-12
    2019-1-13
    2018-2-24
    2018-3-25
    2020-1-16

     

    In my test, your GROUPBY() formula returns a new table like this:

    According to my understand, you want to calculate the sum of each year, or just the current year(2020) , right?

    You could use the following formula:

    Measure =
    CALCULATE (
        SUM ( 'Table1'[Value] ),
        FILTER ( ALL ( 'Table1' ), 'Table1'[Year] = MAX ( 'Table1'[Year] ) )
    )
    SumCurrentYear =
    IF (
        MAX ( 'Table1'[Year] ) = YEAR ( TODAY () ),
        CALCULATE (
            SUM ( 'Table1'[Value] ),
            FILTER ( ALL ( 'Table1' ), 'Table1'[Year] = YEAR ( TODAY () ) )
        )
    )

    Or create a column

    Column =
    CALCULATE ( SUM ( 'Table1'[Value] ), ALLEXCEPT ( Table1, Table1[Year] ) )

    My visualizations are shown below:

    Did I answer your question ? Please mark my reply as solution. Thank you very much.
    If not, please upload some insensitive data samples and expected output.

     

    Best Regards,
    Eyelyn Qin