Forum Discussion

Solle's avatar
Solle
Icon for Helper III rankHelper III
3 years ago

Summarize between selected dates from slicer

Hi All,

I have a measure named "Afkast - Month Afkast" which generates each month return. Then I have a slicer which is using "between" as the style. What I want to accomplish is to generate the sum of monthly returns between two dates selected from the slicer. 

I have tried the below code, but this just gives me from the start of the dates till the selected max value in the data slicer. So it is ignoring the start date in the slicer. 

Afkast - Period Afkast = 
VAR v2 = 
SUMMARIZE(
    FILTER(
        'DimDate',
        'DimDate'[Date]>=MIN(DimDate[Date]) && 'DimDate'[Date]<= MAX('DimDate'[Date])
        ),
        'DimDate'[Date],"Sum",[Afkast - Month afkast])

RETURN
SUMX(v2,[sum])
     
Does anyone know how to accomplish this? Unfortunately I have to have month returns as a measure due to the data structure.

Best Regards,
Solle

3 Replies

    • Solle's avatar
      Solle
      Icon for Helper III rankHelper III

      Hi tamerj1 
      The dax for that measure is 

      Afkast - Month afkast = 
          IF(
              MONTH(SELECTEDVALUE('DimDate'[Date]))=1,
                  SUM('FactAfkast'[Afkast eksl. FX]),
                  SUM(FactAfkast[Afkast eksl. FX])-[Afkast - Previous month afkast])


      Let me know if you have any additional questions. 

      Best Regards,
      Solle

      • Solle's avatar
        Solle
        Icon for Helper III rankHelper III

        And for the measure "Afkast - Previous Month Afkast" it is

        Afkast - Previous month afkast = 
                CALCULATE(SUM('FactAfkast'[Afkast eksl. FX]),PREVIOUSMONTH('DimDate'[Date]))