Forum Discussion
Filter a measure by selected slicer date
- Anonymous1 year ago
Hi AVGUser_PBI ,
Thanks for the reply from rohit1991 / shafiz_p .
Use the following syntax to create a date table that does not require a relationship to be established, this date table projected cost table and real cost table can be used.
Date = ADDCOLUMNS ( CALENDAR ( MIN ( MIN ( 'projected cost'[capture date] ), MIN ( 'real cost'[capture date] ) ), MAX ( MAX ( 'projected cost'[capture date] ), MAX ( 'real cost'[capture date] ) ) ), "Year_Month", FORMAT ( [Date], "YYYY-MM" ) )Create two measures to calculate projected cost and real cost.
Projected Cost = VAR _slicer = SELECTEDVALUE ( 'projected cost'[capture date] ) VAR _currentdate = MAX ( 'Date'[Date] ) VAR _ProjectedCost = CALCULATE ( SUM ( 'projected cost'[projected cost] ), FILTER ( ALLSELECTED ( 'projected cost' ), YEAR ( 'projected cost'[effective date] ) = YEAR ( _currentdate ) && MONTH ( 'projected cost'[effective date] ) = MONTH ( _currentdate ) ) ) RETURN IF ( DATE ( YEAR ( _currentdate ), MONTH ( _currentdate ), 1 ) >= DATE ( YEAR ( _slicer ), MONTH ( _slicer ), 1 ), _ProjectedCost )Real Cost = VAR _slicer = SELECTEDVALUE ( 'projected cost'[capture date] ) VAR _currentdate = MAX ( 'Date'[Date] ) VAR _RealCost = CALCULATE ( SUM ( 'real cost'[real cost] ), FILTER ( ALLSELECTED ( 'real cost' ), YEAR ( 'real cost'[effective date] ) = YEAR ( _currentdate ) && MONTH ( 'real cost'[effective date] ) = MONTH ( _currentdate ) ) ) RETURN IF ( DATE ( YEAR ( _currentdate ), MONTH ( _currentdate ), 1 ) < DATE ( YEAR ( _slicer ), MONTH ( _slicer ), 1 ), _RealCost )Using a matrix visual object, put the Year-month field of the date table into columns, put the two measures created into values, and convert the values into rows.
The final visual is shown below:
The pbix file is attached.
If you have any other questions please feel free to contact me.
Best Regards,
Yang
Community Support TeamIf there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
Hi AVGUser_PBI ,
Thanks for the reply from rohit1991 / shafiz_p .
Use the following syntax to create a date table that does not require a relationship to be established, this date table projected cost table and real cost table can be used.
Date =
ADDCOLUMNS (
CALENDAR (
MIN (
MIN ( 'projected cost'[capture date] ),
MIN ( 'real cost'[capture date] )
),
MAX (
MAX ( 'projected cost'[capture date] ),
MAX ( 'real cost'[capture date] )
)
),
"Year_Month", FORMAT ( [Date], "YYYY-MM" )
)
Create two measures to calculate projected cost and real cost.
Projected Cost =
VAR _slicer =
SELECTEDVALUE ( 'projected cost'[capture date] )
VAR _currentdate =
MAX ( 'Date'[Date] )
VAR _ProjectedCost =
CALCULATE (
SUM ( 'projected cost'[projected cost] ),
FILTER (
ALLSELECTED ( 'projected cost' ),
YEAR ( 'projected cost'[effective date] ) = YEAR ( _currentdate )
&& MONTH ( 'projected cost'[effective date] ) = MONTH ( _currentdate )
)
)
RETURN
IF (
DATE ( YEAR ( _currentdate ), MONTH ( _currentdate ), 1 )
>= DATE ( YEAR ( _slicer ), MONTH ( _slicer ), 1 ),
_ProjectedCost
)Real Cost =
VAR _slicer =
SELECTEDVALUE ( 'projected cost'[capture date] )
VAR _currentdate =
MAX ( 'Date'[Date] )
VAR _RealCost =
CALCULATE (
SUM ( 'real cost'[real cost] ),
FILTER (
ALLSELECTED ( 'real cost' ),
YEAR ( 'real cost'[effective date] ) = YEAR ( _currentdate )
&& MONTH ( 'real cost'[effective date] ) = MONTH ( _currentdate )
)
)
RETURN
IF (
DATE ( YEAR ( _currentdate ), MONTH ( _currentdate ), 1 )
< DATE ( YEAR ( _slicer ), MONTH ( _slicer ), 1 ),
_RealCost
)
Using a matrix visual object, put the Year-month field of the date table into columns, put the two measures created into values, and convert the values into rows.
The final visual is shown below:
The pbix file is attached.
If you have any other questions please feel free to contact me.
Best Regards,
Yang
Community Support Team
If there is any post helps, then please consider Accept it as the solution to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!
fantastic! this worked