Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Dax Sum Help

Hi Guys,   I am trying to calculate a sum of everymonth based from the original month. Jan to Apr = Calculate(Sum(Value),Sweets="Gum", Cat="lollipop")     Jan Feb Mar Apr Sweets    ...
  • mahoneypat's avatar
    mahoneypat
    6 years ago

    That was a good way to share source data.  I wish more people did it like that.  Here is an expression that gets your desired output.  I added a column to your data to make a month column for the visual, but the expression doesn't use it.

     

    Rolling =
    VAR currentdate =
    IF ( HASONEVALUE ( Sweets[Date] ), MIN ( Sweets[Date] ) )
    VAR thismonthtotal =
    CALCULATE (
    SUM ( Sweets[GBP] ),
    OR ( Sweets[Detail] = "Gum", Sweets[Detail] = "Lolly" )
    )
    VAR marchtotal =
    CALCULATE (
    SUM ( Sweets[GBP] ),
    OR ( Sweets[Detail] = "Gum", Sweets[Detail] = "Lolly" ),
    ALL ( Sweets ),
    Sweets[Date] = DATE ( 2020, 3, 1 )
    )
    VAR rollingtotal =
    CALCULATE (
    SUM ( Sweets[GBP] ),
    ALL ( Sweets ),
    Sweets[Date] <= currentdate,
    Sweets[Date] >= DATE ( 2020, 4, 1 )
    )
    RETURN
    IF (
    currentdate >= DATE ( 2020, 4, 1 ),
    rollingtotal + marchtotal,
    thismonthtotal
    )

     

    If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

    Regards,

    Pat