Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AmmoNijjar
Regular Visitor

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 3
v-yuezhe-msft
Employee
Employee

@AmmoNijjar,

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

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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!

@AmmoNijjar,

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

Regards,
Lydia

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.