Forum Discussion

whereismydata's avatar
whereismydata
Icon for Resolver IV rankResolver IV
5 years ago
Solved

Calculate with seleced value

Hi,

 

can somebody please help me out here.

[Total] is a measure (a simple Sum(Revenue) )

Calendar is a calendar table. There is a relationship between the calendar table and the revenue table

This works:

 

Total this year = 
VAR vYear = 2020
RETURN
CALCULATE([Total], 'Calendar'[Year] = vYear)

 

Gives me the correct number

 

But this doesn't:

 

Total this year = 
VAR vYear = SELECTEDVALUE('Calendar'[Year])
RETURN
CALCULATE([Total], 'Calendar'[Year] = vYear)

 

The result of this is (BLANK)

I have a slicer where the user can select only one year, no multi select.

 

Thank you in advance

  • whereismydata , first of all if they are related then

    CALCULATE([Total])  should get the filter

     

    or try like

    Total this year =
    VAR vYear = SELECTEDVALUE('Calendar'[Year])
    RETURN
    CALCULATE([Total], filter('Calendar','Calendar'[Year] = vYear))

     

    or


    Total this year =
    VAR vYear = SELECTEDVALUE('Calendar'[Year])
    RETURN
    CALCULATE([Total], filter(all('Calendar'),'Calendar'[Year] = vYear))

2 Replies

  • whereismydata , first of all if they are related then

    CALCULATE([Total])  should get the filter

     

    or try like

    Total this year =
    VAR vYear = SELECTEDVALUE('Calendar'[Year])
    RETURN
    CALCULATE([Total], filter('Calendar','Calendar'[Year] = vYear))

     

    or


    Total this year =
    VAR vYear = SELECTEDVALUE('Calendar'[Year])
    RETURN
    CALCULATE([Total], filter(all('Calendar'),'Calendar'[Year] = vYear))

  • Hi amitchandak 

    I was using filter(all ....) before, but it didn't work. Tried it again and now it works. Should call it a day 😄

    Thank you for taking the time looking at my problem!

     

    Best