Forum Discussion
Dynamic Measure(Year Till date)
- 5 years ago
bilalkhokar73
Can you try it:MEASUREYEARTILL = VAR __lastsalesdate = CALCULATE(MAX(sales[datei] ),REMOVEFILTERS()) VAR day1 = DAY(__lastsalesdate) VAR MONTH1 = MONTH(__lastsalesdate) VAR __filterdate = DATE(MAX (tm_date[year_id]), MONTH1, day1 ) RETURN CALCULATE ( SUM(sales[amt]), tm_date[Date] <= __filterdate, REMOVEFILTERS ( tm_date), VALUES (tm_date[year_id] ) )
bilalkhokar73
So you want to show sales by year but on each year, the amount should be shown only from 1st Jan to the date and month of the lastest year date and month. create the following formula, make sure you have all required columns are there in your dates table, add the years and the total sales and this measure to the visual and check.
Salessameperdiod =
VAR __lastsalesdate =
CALCULATE ( MAX ( Sales[datei] ), REMOVEFILTERS () )
VAR __day = DAY ( __lastsalesdate )
VAR __month = MONTH ( __lastsalesdate )
VAR __filterdate = DATE ( MAX ( tm_date[Year] ), __month, __day )
RETURN
CALCULATE (
SUM(sales[amt]),
tm_date[Date] <= __filterdate,
REMOVEFILTERS ( tm_date),
VALUES ( tm_date[Year] )
)
I used thsi one but i got an error that
Calculation error in measure 'sales'[MEASUREYEARTILL]: An argument of function 'DATE' has the wrong data type or the result is too large or too small.
MEASUREYEARTILL =
VAR __lastsalesdate=CALCULATE(MAX(sales[datei] ),REMOVEFILTERS())
VAR day1=DAY(LASTDATE(sales[datei]))
VAR MONTH1=MONTH(__lastsalesdate)
VAR __filterdate = DATE(MAX (tm_date[Date] ), MONTH1, day1 )
RETURN
CALCULATE (SUM(sales[amt]),
tm_date[Date] <= __filterdate,
REMOVEFILTERS ( tm_date),
VALUES (tm_date[year_id] )
)