Forum Discussion
Anonymous
2 years agoNot applicable
Measure giving wrong answer
Please review the attached 1 screenshot. It is from the visual. I am doing rolling 6 month sum but it is showing me unexpected result. Here is the DAX: TotalUsers_6M = VAR LATEST_MONTH = MAX(r...
- 2 years ago
Try this:
TotalUsers_6M = VAR _LATEST_MONTH = MAX('Date'[Fiscal Date]) Var _END_DATE = EOMONTH(_LATEST_MONTH,0) VAR _START_DATE = EOMONTH(_END_DATE,-6)+1 VAR _MAXDATE = MAX(Sheet1[order_date]) VAR _VALUE = CALCULATE( SUM(Sheet1[Net Revenue GBP]),DATESBETWEEN('Date'[Fiscal Date],_START_DATE,_END_DATE)) VAR _RESULT = IF( EOMONTH(_MAXDATE,0) >= _LATEST_MONTH, _VALUE) RETURN _RESULT - 2 years ago
It can work with DATESINPERIOD if you protect your date by wrapping it around EOMONTH.
Basically you need to make it clear to the code that needs to take the full period of the month.
I re wrote your logic below.
Debug = VAR LATEST_MONTH = MAX(Sheet1[order_date]) Var _END_DATE = EOMONTH(LATEST_MONTH,0) var final_date = if( ISBLANK( year(_END_DATE) ) ,BLANK(), _END_DATE ) VAR DATES_IN_PERIOD_TABLE_PY = DATESINPERIOD ('Date'[Fiscal Date], final_date, -6, MONTH) VAR _Result = CALCULATE( SUM(Sheet1[Net Revenue GBP]),DATES_IN_PERIOD_TABLE_PY) RETURN _Result
Alex87
2 years agoSolution Sage
Hello Anonymous ,
There is no issue in the solution provided. The DAX calculation is correct as shown in the print screen. Now, you might have some specificities or issues inside your data. I will gladly help if you can provide a sample dummy data that reproduces the issue you are describing. I am unfortunatelly unable to imagine what is the problem without having the data.
Thanks
Anonymous
2 years agoNot applicable
https://drive.google.com/drive/folders/12LNhJs-WwWQ-_MOXLmWeA83TO59OvsCb Please download the file from the given link Alex87