Forum Discussion
Fantmas
2 years agoHelper III
Treat as function not working with variable
Hi Everyone,
I have the following DAX expression my issue is when I use this expression with le variable _Year is returns me a blank when I harcode the period I want example "2021.TOTAL", it is working and I do not understand what is the issue has I check the variable, if it is a text or a case issue but everything is align with what I need, any clue how to fix it ?
Act Previous Years = VAR default_year = YEAR(LASTDATE(ALL(DimDate[Date by Years])))-1
VAR selected_year = YEAR(SELECTEDVALUE('DimDate'[Date by Years]))-1
Var _Year = SWITCH(
TRUE(),
ISFILTERED(DimDate[Date by Years]),
CONCATENATE(CONVERT(selected_year,STRING), ".TOTAL"),
CONCATENATE(CONVERT(default_year,STRING), ".TOTAL")
)
VAR _Type = "ACTUAL - Actual"
VAR _Result = CALCULATE(
[Actual],
TREATAS(
{
_Year
},
'Data'[Period Available]
),
TREATAS(
{
_Type
},
'Data'[Type]
)
)
RETURN
_Result
1 Reply
- amustafaSolution Sage
You can do some debugging by creating individual measures for each part of your expression (like for default_year, selected_year, and _Year) and use them in a table visualization to see their individual outputs. This can help you pinpoint where the problem lies.