cancel
Showing results for
Did you mean:
Helper II

## Filter measure based on Booking Date and Arrival Date

Need help to filter a measure based on booking date and arrival date. The 1st table is the actual value based on the year selected and the 2nd table are all values based on arrival ( I removed the interaction of the slicer ). The objective is to return values of previous years based on the selected year in the slicer of ArrDate. So for example, selected slicer is 2021. I need to return the pax count of the previous years on the same date. How many arrivals do we have in 2020 sold until July 24 2020 and below? How many arrivals do we have on 2019 sold until July 24 2019 below? and so on.

Tried this measure but I'm not getting the correct values.

``````Measure =
VAR _SelectedYear = SELECTEDVALUE ( ArrDate[Year] )
VAR _DateComparison =  DATE ( _SelectedYear - 1, MONTH ( TODAY ()), DAY ( TODAY ()) )
RETURN
CALCULATE (
[Pax Count],
FILTER ( 'ResDate', 'ResDate'[Date] <= _DateComparison )
)``````

2 Calendar Tables

1 ACCEPTED SOLUTION
Community Support

Hi @justivan ,

After my research, there is no need to establish a relationship between the calendar table and the main table.

This is my example, you can refer to it.

Main table:

Calendar table:

``calendar = ADDCOLUMNS(CALENDAR(MIN('Table'[Date]),MAX('Table'[Date])),"Year",YEAR([Date]))``

Create the following measure

``````Measure =
VAR _sel =
SELECTEDVALUE ( 'calendar'[Year] )
RETURN
CALCULATE (
SUM ( 'Table'[Value] ),
FILTER (
'Table',
(
[Date]
<= DATE ( _sel - 1, MONTH ( TODAY () ), DAY ( TODAY () ) )
&& [Date]
>= DATE ( _sel - 1, 1, 1 )
)
|| (
[Date]
<= DATE ( _sel - 2, MONTH ( TODAY () ), DAY ( TODAY () ) )
&& [Date]
>= DATE ( _sel - 2, 1, 1 )
)
)
)
``````

Check more details from the attachment.

Best Regards,

Stephen Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 REPLIES 4
Community Support

Hi @justivan ,

After my research, there is no need to establish a relationship between the calendar table and the main table.

This is my example, you can refer to it.

Main table:

Calendar table:

``calendar = ADDCOLUMNS(CALENDAR(MIN('Table'[Date]),MAX('Table'[Date])),"Year",YEAR([Date]))``

Create the following measure

``````Measure =
VAR _sel =
SELECTEDVALUE ( 'calendar'[Year] )
RETURN
CALCULATE (
SUM ( 'Table'[Value] ),
FILTER (
'Table',
(
[Date]
<= DATE ( _sel - 1, MONTH ( TODAY () ), DAY ( TODAY () ) )
&& [Date]
>= DATE ( _sel - 1, 1, 1 )
)
|| (
[Date]
<= DATE ( _sel - 2, MONTH ( TODAY () ), DAY ( TODAY () ) )
&& [Date]
>= DATE ( _sel - 2, 1, 1 )
)
)
)
``````

Check more details from the attachment.

Best Regards,

Stephen Tao

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Super User III

Hi,

We do not need the ResDate table.  In your second visual, drag Year and Month from the ArrDate table.  Write this measure

=calculate([Pax count],datesbetween(Arrdate,min(arrDate),date(min(arrdate[year]),min(arrdate[monthnum]),day(today()))))

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com
Helper II

Hi @Ashish_Mathur ,

I tried the above expression but I'm getting an error.

Super User III

Hi,

Try this

=calculate([Pax count],datesbetween(Arrdate[date],min(arrDate[date]),date(min(arrdate[year]),min(arrdate[monthnum]),day(today()))))

Regards,
Ashish Mathur
http://www.ashishmathur.com

Announcements

#### Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.