Forum Discussion
Calculate Actual booking
- Anonymous1 year ago
Hi Peter2023
First, change the type of "Monthnumber"
Then try the following measure:Measure = VAR _month = SELECTEDVALUE('Date Lib'[Monthnumber]) VAR _current_booking = [Booking] VAR _current_cancel = [Cancel] VAR _current_retails = [Retails] VAR _previous_booking = SUMX(FILTER(ALL('Date Lib'),'Date Lib'[Monthnumber] <= _month-1),[Booking]) VAR _previous_cancel = SUMX(FILTER(ALL('Date Lib'),'Date Lib'[Monthnumber] <= _month-1),[Cancel]) VAR _previous_retails = SUMX(FILTER(ALL('Date Lib'),'Date Lib'[Monthnumber] <= _month-1),[Retails]) RETURN _current_booking + _previous_booking -_current_cancel - _current_retails -_previous_cancel - _previous_retailsResult:
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous1 year ago
Hi Peter2023
First, use the following dax to get the week number:weeknum = WEEKNUM('Date lib'[Date])Then try the following Measure:
Actual booking = VAR _month = SELECTEDVALUE('Date lib'[Monthnumber]) VAR _week = SELECTEDVALUE('Date lib'[weeknum]) VAR _current_booking = [Booking] VAR _current_cancel = [Cancel] VAR _current_retails = [Retails] VAR _previous_booking_month = SUMX(FILTER(ALL('Date lib'),'Date lib'[Monthnumber] <= _month-1),[Booking]) VAR _previous_cancel_month = SUMX(FILTER(ALL('Date lib'),'Date lib'[Monthnumber] <= _month-1),[Cancel]) VAR _previous_retails_month = SUMX(FILTER(ALL('Date lib'),'Date lib'[Monthnumber] <= _month-1),[Retails]) VAR _previous_booking_week = SUMX(FILTER(ALL('Date lib'),'Date lib'[weeknum] <= _week-1),[Booking]) VAR _previous_cancel_week = SUMX(FILTER(ALL('Date lib'),'Date lib'[weeknum] <= _week-1),[Cancel]) VAR _previous_retails_week = SUMX(FILTER(ALL('Date lib'),'Date lib'[weeknum] <= _week-1),[Retails]) RETURN IF(ISINSCOPE('Date lib'[weeknum]),_current_booking + _previous_booking_week -_current_cancel - _current_retails -_previous_cancel_week - _previous_retails_week,_current_booking + _previous_booking_month -_current_cancel - _current_retails -_previous_cancel_month - _previous_retails_month)Result:
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Peter2023
First, change the type of "Monthnumber"
Then try the following measure:
Measure =
VAR _month = SELECTEDVALUE('Date Lib'[Monthnumber])
VAR _current_booking = [Booking]
VAR _current_cancel = [Cancel]
VAR _current_retails = [Retails]
VAR _previous_booking = SUMX(FILTER(ALL('Date Lib'),'Date Lib'[Monthnumber] <= _month-1),[Booking])
VAR _previous_cancel = SUMX(FILTER(ALL('Date Lib'),'Date Lib'[Monthnumber] <= _month-1),[Cancel])
VAR _previous_retails = SUMX(FILTER(ALL('Date Lib'),'Date Lib'[Monthnumber] <= _month-1),[Retails])
RETURN
_current_booking + _previous_booking -_current_cancel - _current_retails -_previous_cancel - _previous_retails
Result:
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Peter20231 year ago
Helper I
Thank you, you make my day!
- Peter20231 year ago
Helper I
Anonymous Sorry if I disturb you again. But how to use the measure with a day or week number? The result is incorrect after I add it. .
After add week
Date library code with week number and week range:
SpoilerDate lib =VAR minDate = MIN(booking[bookingdate])VAR maxDate = MAX(booking[bookingdate]
)RETURNADDCOLUMNS(CALENDAR(DATE(YEAR(minDate), 1, 1), DATE(YEAR(maxDate), 12, 31)),"DateAsInteger", FORMAT([Date], "YYYYMMDD"),"Year", YEAR([Date]),"No", VALUE([Date]),"Monthnumber", FORMAT([Date], "MM"),"YearMonthnumber", FORMAT([Date], "YYYY/MM"),"YearMonthShort", FORMAT([Date], "YYYY/mmm"),"MonthNameShort", FORMAT([Date], "mmm"),"MonthNameLong", FORMAT([Date], "mmmm"),"DayOfWeekNumber", WEEKDAY([Date]),"DayOfWeek", FORMAT([Date], "dddd"),"DayOfWeekShort", FORMAT([Date], "ddd"),"Quarter", "Q" & FORMAT([Date], "Q"),"YearQuarter", FORMAT([Date], "YYYY") & "/Q" & FORMAT([Date], "Q"),"WeekInMonth",VAR DayOfMonth = DAY([Date])RETURNSWITCH(TRUE(),DayOfMonth <= 7, 1,DayOfMonth <= 14, 2,DayOfMonth <= 21, 3,4),"WeekRange",VAR DayOfMonth = DAY([Date])VAR WeekNum = SWITCH(TRUE(),DayOfMonth <= 7, 1,DayOfMonth <= 14, 2,DayOfMonth <= 21, 3,4)VAR FirstDayOfMonth = DATE(YEAR([Date]), MONTH([Date]), 1)VAR LastDayOfMonth = EOMONTH([Date], 0)VAR WeekStartDate = FirstDayOfMonth + (WeekNum - 1) * 7VAR WeekEndDate =IF(WeekNum = 4,LastDayOfMonth,WeekStartDate + 6)RETURN FORMAT(WeekStartDate, "dd/MM") & " - " & FORMAT(WeekEndDate, "dd/MM"))- Anonymous1 year agoNot applicable
Hi Peter2023
Please provide sample data that fully covers your issue and the expected outcome based on the sample data you provided. Please remove any sensitive data in advance.
Best Regards,
Jayleny
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Peter20231 year ago
Helper I
Anonymous Thank you for the help.
Please check my file: actual booking+expect result
https://drive.google.com/drive/folders/1wcDQtGIvQhVzjtPnZIML8NsxcZYzIUPn?usp=sharingExp: In Sep, actual booking in week 3 is 12 but currently, it's showing -3