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,
Last visit stands for last visit to a specific center. For instance, if date threshold is from 01/01/2023 to 10/02/2023, lines with last visit will be:
Shop//Date of visit(DD/MM/YYYY)//Presence of our product // is it last visit?
| Center A | 01/01/2023 | YES | No last |
| Center B | 02/01/2023 | NO | No last |
| Center C | 04/01/2023 | YES | No last |
| Center D | 15/01/2023 | NO | No last |
| Center B | 02/02/2023 | YES | No last |
| Center B | 04/02/2023 | YES | Last |
| Center A | 08/02/2023 | NO | No last |
| Center C | 09/02/2023 | NO | Last |
| Center D | 02/02/2023 | NO | Last |
| Center A | 10/02/2023 | YES | Last |
just to clear this, if we selected date from 01/01/2023 to 31/01/2023, the resulting table would be:
Shop//Date of visit(DD/MM/YYYY)//Presence of our product // is it last visit?
| Center A | 01/01/2023 | YES | Last |
| Center B | 02/01/2023 | NO | Last |
| Center C | 04/01/2023 | YES | Last |
| Center D | 15/01/2023 | NO | Last |
Hope it clarifies,
Thanks
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
- Anonymous3 years agoNot applicable
Thanks, it worked perfectly