Forum Discussion
Variable column depending on filters
- Anonymous3 years ago
Hi Anonymous ,
I updated your sample pbix file(see the attachment), please find the details in new created page [Page 2]. You can follow the steps below to get it:
1. Update the formula of measure [Last visit filter] as below
Last visit filter = VAR _mindate = MIN ( 'CALENDAR'[Date] ) VAR _maxdate = MAX ( 'CALENDAR'[Date] ) VAR _selshop = SELECTEDVALUE ( 'Date of visit'[Shop] ) VAR _selvisitdate = SELECTEDVALUE ( 'Date of visit'[Date of visit] ) VAR _lastvisitdate = CALCULATE ( MAX ( 'Date of visit'[Date of visit] ), FILTER ( ALLSELECTED ( 'Date of visit' ), 'Date of visit'[Shop] = _selshop ) ) RETURN IF ( _selvisitdate < _mindate || _selvisitdate > _maxdate, BLANK (), IF ( _selvisitdate = _lastvisitdate && _selvisitdate >= _mindate && _selvisitdate <= _maxdate, "Y", "N" ) )2. Create a dimension table as below
3. Update the formula of measure [Presence Yes] as below
Presence Yes = VAR _filter = [Last visit filter] VAR _tab = SUMMARIZE ( 'Date of visit', 'Date of visit'[Shop], 'Date of visit'[Date of visit], 'Date of visit'[Presence of our product], "@lastvisit", _filter ) RETURN COUNTX ( FILTER ( _tab, [@lastvisit] IN ALLSELECTED ( 'Last Visit'[Last Visit] ) && [Presence of our product] = "Yes" ), [Date of visit] )4. Create a measure as below and put it onto the column chart to replace the measure [Presence Yes]
Measure = SUMX ( GROUPBY ( 'Date of visit', 'Date of visit'[Shop], 'Date of visit'[Date of visit] ), [Presence Yes] )Best Regards
Hi Anonymous ,
I updated your sample pbix file(see the attachment), please find the details in new created page [Page 2]. You can follow the steps below to get it:
1. Update the formula of measure [Last visit filter] as below
Last visit filter =
VAR _mindate =
MIN ( 'CALENDAR'[Date] )
VAR _maxdate =
MAX ( 'CALENDAR'[Date] )
VAR _selshop =
SELECTEDVALUE ( 'Date of visit'[Shop] )
VAR _selvisitdate =
SELECTEDVALUE ( 'Date of visit'[Date of visit] )
VAR _lastvisitdate =
CALCULATE (
MAX ( 'Date of visit'[Date of visit] ),
FILTER ( ALLSELECTED ( 'Date of visit' ), 'Date of visit'[Shop] = _selshop )
)
RETURN
IF (
_selvisitdate < _mindate
|| _selvisitdate > _maxdate,
BLANK (),
IF (
_selvisitdate = _lastvisitdate
&& _selvisitdate >= _mindate
&& _selvisitdate <= _maxdate,
"Y",
"N"
)
)
2. Create a dimension table as below
3. Update the formula of measure [Presence Yes] as below
Presence Yes =
VAR _filter = [Last visit filter]
VAR _tab =
SUMMARIZE (
'Date of visit',
'Date of visit'[Shop],
'Date of visit'[Date of visit],
'Date of visit'[Presence of our product],
"@lastvisit", _filter
)
RETURN
COUNTX (
FILTER (
_tab,
[@lastvisit]
IN ALLSELECTED ( 'Last Visit'[Last Visit] )
&& [Presence of our product] = "Yes"
),
[Date of visit]
)
4. Create a measure as below and put it onto the column chart to replace the measure [Presence Yes]
Measure =
SUMX (
GROUPBY (
'Date of visit',
'Date of visit'[Shop],
'Date of visit'[Date of visit]
),
[Presence Yes]
)
Best Regards
Thanks, it worked perfectly