Forum Discussion

yo_peralta23's avatar
yo_peralta23
Frequent Visitor
6 years ago
Solved

Problem using Datediff and Sumx (Connected to Tabular Model)

Hi,

Im trying to do a new measure called RealAging starting from variables stored in my Tabular Model:

 

 

 

RealAging = 
SWITCH(
	TRUE();
	SUMX(DW_DS_STAFFING_CURRENT;DW_DS_STAFFING_CURRENT[start_date])<TODAY();
	DATEDIFF(
		SUMX(DW_DS_STAFFING_CURRENT;DW_DS_STAFFING_CURRENT[start_date]);
		TODAY();
		DAY);
	SUMX(DW_DS_STAFFING_CURRENT;DW_DS_STAFFING_CURRENT[start_date])>TODAY();
	DATEDIFF(
		TODAY();
		SUMX(DW_DS_STAFFING_CURRENT;DW_DS_STAFFING_CURRENT[start_date]);
		DAY)*(-1);
	0
)

 

 

 

It seems good, no errors reported. But when I use this variable in a visual, appears an error near that says semantic or syntax error about the second DATEDIFF() function. I tried to replace the SUMX(DW_DS_STAFFING_CURRENT;DW_DS_STAFFING_CURRENT[start_date]); expresion by a fixed value in this second DATEDIFF() and works fine. Seems like the problem is this SUMX(), but in the first DATEDIFF() I also use the SUMX() and works fine.
Can anybody explain me what I´m doing wrong?
Thanks in advance

  • sturlaws's avatar
    sturlaws
    6 years ago

    Since I don't know anything about your data, this is a bit of guesswork, but try to rewrite your code to this:

    real aging = 
    var _currentDate = calculate(selectedvalue(DW_DS_...[start date]))
    return
    datediff(_currentDate;today();day)

     

    If you need more specific help, you could try sharing some sample data or a sample pbix-file.


6 Replies

    • yo_peralta23's avatar
      yo_peralta23
      Frequent Visitor

      Because is the only way I was found to take the date without errors. If I just try to write:

      DATEDIFF(
      		TODAY();
      		[start_date];
      		DAY)

      An errors says: "Cannot find name '[start_date]'."

      Exists any other way to do this?

      Thanks for your time

      • sturlaws's avatar
        sturlaws
        Resident Rockstar

        Is [start date] a measure or a column?