Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago

DAX issue with Value Type

Hi All,

 

I have an issue with weekly calculations in DAX for Previous YTD.

My calendar has a column for YearFiscalWeek (eg: 201801) and the latest entry is always the most recent (so I add the last calendar row every week when I update the new weekly dataset).

 

I have managed to get the current YTD working correctly using the following measure:

 

_Value YTD:=IF([_Value All Period]>0,
CALCULATE([_Value All Period],
FILTER('Calendar','Calendar'[YearFiscalWeek]<=[CY FW]),'Calendar'[YearFiscalWeek]>=201801),
BLANK())

 

where CY FW:=max('Calendar'[YearFiscalWeek]) - giving 201806

and Value All Period is the sum of my sales.

 

However when I am trying to get the Previous YTD I get a blank result:

 

_Value YTD Previous:=IF([_Value All Period]>0,
CALCULATE([_Value All Period],
FILTER('Calendar','Calendar'[YearFiscalWeek]<=VALUE([PY FW])),'Calendar'[YearFiscalWeek]>=201701),
BLANK())

 

where PY FW:=([CY FW]-100) - giving 201706.

 

However if I input 201706 in place of [PY FW] in the "_Value YTD Previous" measure it works, so it is as if the measure [PY FW] is not being recognised as a value (I have also tried changing the measure to PY FW:=value([CY FW]-100). 

 

In both scenaris [PW FW] does show what I am expecting to see in the measure (201706).

 

I hope this is clear, any help would be greatly appreciated!

 

 

 

 

 

 

 

 

3 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Anonymous,

    The data type of [PY FW] and [CY FW] measures are whole number, right? If so, why not directly use the following DAX? VALUE() function is used to convert a text string that represents a number to a number.

    _Value YTD Previous:=IF([_Value All Period]>0,
    CALCULATE([_Value All Period],
    FILTER('Calendar','Calendar'[YearFiscalWeek]<=[PY FW]),'Calendar'[YearFiscalWeek]>=201701),
    BLANK())
    
     



    Regards,
    Lydia

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Lydia,

       

      Thanks for the response.

      Yes correct,  they are both whole numbers. Sorry my mistake, I did try with and without value (I only tried with VALUE when initially it did not work without Value. so I did actually start by using the formula you suggested:

       

      _Value YTD Previous:=IF([_Value All Period]>0,
      CALCULATE([_Value All Period],
      FILTER('Calendar','Calendar'[YearFiscalWeek]<=[PY FW]),'Calendar'[YearFiscalWeek]>=201701),
      BLANK())

       

       The strange thing is, in my YTD measure, [CY FW] is being used and works fine, however when I refer to [PY FW] (which is [CY FW]-100, the correct figure shows in the measure for [PY FW] but it does not give me any value for the YTD previous unless I manually type in the [PY FW] as the actual number!

      • Anonymous's avatar
        Anonymous
        Not applicable

        Anonymous,

        Could you please share dummy data of the tables so that I can test?

        Regards,
        Lydia