Forum Discussion

moesteez's avatar
moesteez
Helper I
5 years ago

Variables in the date function

Hi all,

 

Im trying to pass a date into a calculated dax measure but for some reason Im getting a blank value everytime.

 

This is what I have so far:

 

VAR year = YEAR(FIRSTDATE('Calendar 2'[Date]))
VAR month = MONTH(FIRSTDATE('Calendar 2'[Date]))
VAR day = DAY(FIRSTDATE('Calendar 2'[Date]))
 
Ive tested each of these variables and they are returning the correct year, month and day respectively. But when I use them in the next step:
 
CALCULATE([Quantity], 'Calendar'[Date] = DATE(year, month , day ) )
 
I get a blank value. If I swap out the variables for my own text the measure works fine. Am I doing something wrong here?
 
Thanks
 

4 Replies

  • moesteez , Can you try the min date?

     

     

    Measure =
    VAR _min = Minx(allselected('Calendar 2'), 'Calendar 2'[Date]))
    return
    CALCULATE([Quantity], filter('Calendar', 'Calendar'[Date] = _min ))

    • moesteez's avatar
      moesteez
      Helper I

      Thanks amitchandak , but this also returns a blank value for me. Im not sure why because in theory this should work

  • When i call the _min variable I get the correct date. So that part is working fine.

    • v-easonf-msft's avatar
      v-easonf-msft
      Community Support

      Hi,  moesteez 

      I suspect that the problem lies mainly in your [quantity].

      You can consider directly replacing [quantity] with the complete formula.

       

      Best Regards,
      Community Support Team _ Eason