Lets suppose we have a Data Model as follows with Orders and Sales details.
Sales Rolling12M_Total =
VAR NumOfMonths=12
VAR LastSelectDate=MAX('tbl_Calendar'[cDate])
VAR PeriodRange=DATESINPERIOD('tbl_Calendar'[cDate], LastSelectDate,-NumOfMonths,MONTH)
VAR Result=CALCULATE(
SUMX(VALUES(tbl_Calendar[Month_No]), [Total Sales]),
VAR NumOfMonths=12
VAR LastSelectDate=MAX('tbl_Calendar'[cDate])
VAR PeriodRange=DATESINPERIOD('tbl_Calendar'[cDate], LastSelectDate,-NumOfMonths,MONTH)
VAR Result=CALCULATE(
SUMX(VALUES(tbl_Calendar[Month_No]), [Total Sales]),
PeriodRange
)
VAR LastDateOfSales=MAX(tbl_OrderDetails[Order_Date])
VAR FirstSelectedDate=MIN('tbl_Calendar'[cDate])
RETURN
IF(FirstSelectedDate<=LastDateOfSales,Result)
VAR LastDateOfSales=MAX(tbl_OrderDetails[Order_Date])
VAR FirstSelectedDate=MIN('tbl_Calendar'[cDate])
RETURN
IF(FirstSelectedDate<=LastDateOfSales,Result)
VAR NumOfMonths=12
VAR LastSelectDate=MAX('tbl_Calendar'[cDate])
VAR PeriodRange=DATESINPERIOD('tbl_Calendar'[cDate], LastSelectDate,-NumOfMonths,MONTH)
VAR Result=CALCULATE(
AVERAGEX(VALUES(tbl_Calendar[Month_No]), [Total Sales]),
PeriodRange
)
VAR LastDateOfSales=MAX(tbl_OrderDetails[Order_Date])
VAR FirstSelectedDate=MIN('tbl_Calendar'[cDate])
RETURN
IF(FirstSelectedDate<=LastDateOfSales,Result)
VAR LastDateOfSales=MAX(tbl_OrderDetails[Order_Date])
VAR FirstSelectedDate=MIN('tbl_Calendar'[cDate])
RETURN
IF(FirstSelectedDate<=LastDateOfSales,Result)
Notes:
LastDateOfSales - is the last date for which the Sales is available
FirstSelectedDate - is the first visible date of each Selected Date/Month in the Visual.
The condition IF(FirstSelectedDate<=LastDateOfSales,Result) will ensures the result for only the available Sales dates.
No comments:
Post a Comment
Hi User, Thank You for visiting My Blog. Please post your genuine Feedback or comments only related to this Blog Posts. Please do not post any Spam comments or Advertising kind of comments which will be Ignored.