Forum Discussion
Last 12 months data from current month
- Anonymous3 years ago
Hi Anonymous ,
Please try below steps:
1. below is my test table
Table:
2. create measure with below dax formula
Combine = VAR cur_date = SELECTEDVALUE ( 'Table'[Date] ) VAR _value = YEAR ( cur_date ) * 100 + MONTH ( cur_date ) RETURN _valueRK = RANKX(ALL('Table'),[Combine],,ASC,Dense)Measure = VAR last_date = MAXX ( ALL ( 'Table' ), [Date] ) VAR rk = CALCULATE ( [RK], FILTER ( ALL ( 'Table' ), [Date] = last_date ) ) VAR tmp = CALCULATETABLE ( VALUES ( 'Table'[Date] ), FILTER ( ALL ( 'Table' ), [RK] > rk - 12 ) ) VAR cur_date = SELECTEDVALUE ( 'Table'[Date] ) RETURN IF ( cur_date IN tmp, 1, 0 )Year and Qtr = VAR cur_date = SELECTEDVALUE ( 'Table'[Date] ) VAR cur_qtr = [Qtr] VAR _value = YEAR ( cur_date ) * 100 + cur_qtr RETURN _valueRK For Qtr = RANKX(ALL('Table'),[Year and Qtr],,ASC,Dense)Condition for Qtr = VAR last_date = MAXX ( ALL ( 'Table' ), [Date] ) VAR rk = CALCULATE ( [RK For Qtr], FILTER ( ALL ( 'Table' ), [Date] = last_date ) ) VAR tmp = CALCULATETABLE ( VALUES ( 'Table'[Date] ), FILTER ( ALL ( 'Table' ), [RK For Qtr] > rk - 4 ) ) VAR cur_date = SELECTEDVALUE ( 'Table'[Date] ) RETURN IF ( cur_date IN tmp, 1, 0 )Year and Week Num = VAR cur_data = SELECTEDVALUE ( 'Table'[Date] ) VAR wn = [Week Num] RETURN YEAR ( cur_data ) * 100 + wnRK for Week Num = RANKX(ALL('Table'),[Year and Week Num],,ASC,Dense)Condition for Week Num = VAR last_date = MAXX ( ALL ( 'Table' ), [Date] ) VAR rk = CALCULATE ( [RK for Week Num], FILTER ( ALL ( 'Table' ), [Date] = last_date ) ) VAR tmp = CALCULATETABLE ( VALUES ( 'Table'[Date] ), FILTER ( ALL ( 'Table' ), [RK for Week Num] > rk - 52 ) ) VAR cur_date = SELECTEDVALUE ( 'Table'[Date] ) RETURN IF ( cur_date IN tmp, 1, 0 )3. add a table visual with fields, add measure to it filter pane
Please refer the attached .pbix file.
Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quick
Hi Anonymous ,
Please try below steps:
1. below is my test table
Table:
2. create measure with below dax formula
Combine =
VAR cur_date =
SELECTEDVALUE ( 'Table'[Date] )
VAR _value =
YEAR ( cur_date ) * 100
+ MONTH ( cur_date )
RETURN
_value
RK = RANKX(ALL('Table'),[Combine],,ASC,Dense)Measure =
VAR last_date =
MAXX ( ALL ( 'Table' ), [Date] )
VAR rk =
CALCULATE ( [RK], FILTER ( ALL ( 'Table' ), [Date] = last_date ) )
VAR tmp =
CALCULATETABLE (
VALUES ( 'Table'[Date] ),
FILTER ( ALL ( 'Table' ), [RK] > rk - 12 )
)
VAR cur_date =
SELECTEDVALUE ( 'Table'[Date] )
RETURN
IF ( cur_date IN tmp, 1, 0 )
Year and Qtr =
VAR cur_date =
SELECTEDVALUE ( 'Table'[Date] )
VAR cur_qtr = [Qtr]
VAR _value =
YEAR ( cur_date ) * 100 + cur_qtr
RETURN
_value
RK For Qtr = RANKX(ALL('Table'),[Year and Qtr],,ASC,Dense)Condition for Qtr =
VAR last_date =
MAXX ( ALL ( 'Table' ), [Date] )
VAR rk =
CALCULATE ( [RK For Qtr], FILTER ( ALL ( 'Table' ), [Date] = last_date ) )
VAR tmp =
CALCULATETABLE (
VALUES ( 'Table'[Date] ),
FILTER ( ALL ( 'Table' ), [RK For Qtr] > rk - 4 )
)
VAR cur_date =
SELECTEDVALUE ( 'Table'[Date] )
RETURN
IF ( cur_date IN tmp, 1, 0 )
Year and Week Num =
VAR cur_data =
SELECTEDVALUE ( 'Table'[Date] )
VAR wn = [Week Num]
RETURN
YEAR ( cur_data ) * 100 + wn
RK for Week Num = RANKX(ALL('Table'),[Year and Week Num],,ASC,Dense) Condition for Week Num =
VAR last_date =
MAXX ( ALL ( 'Table' ), [Date] )
VAR rk =
CALCULATE ( [RK for Week Num], FILTER ( ALL ( 'Table' ), [Date] = last_date ) )
VAR tmp =
CALCULATETABLE (
VALUES ( 'Table'[Date] ),
FILTER ( ALL ( 'Table' ), [RK for Week Num] > rk - 52 )
)
VAR cur_date =
SELECTEDVALUE ( 'Table'[Date] )
RETURN
IF ( cur_date IN tmp, 1, 0 )
3. add a table visual with fields, add measure to it filter pane
Please refer the attached .pbix file.
Best regards,
Community Support Team_ Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quick
Hi,
I am in the same situation and was trying to apply this solution but this does not work when applied to matrix visual as visual level filter.
Appreciate if you have any suggestion.
Regards,
Sagar