Forum Discussion
DAX Measure for Date Problem
- Anonymous5 years ago
Hi mayurwadhwani ,
I updated the formula in the original sample pbix file, please check whether it is ok.
Measure = VAR _count = COUNTROWS ( ALLSELECTED ( 'DateDim'[Date].[Year] ) ) VAR _count1 = CALCULATE ( DISTINCTCOUNT ( 'DateDim'[Date].[Year] ), ALL ( 'DateDim' ) ) RETURN IF ( _count = _count1, CALCULATE ( DISTINCTCOUNT ( 'Members'[pkey] ) ), CALCULATE ( [Total Count distinct pkey], FILTER ( ALLSELECTED ( 'DateDim' ), 'DateDim'[Date] = MAX ( 'DateDim'[Date] ) ) ) )Best Regards
Hi mayurwadhwani ,
You can create a measure as below:
Total Count distinct pkey =
VAR _selyear =
SELECTEDVALUE ( 'DateDim'[Date].[Year] )
RETURN
CALCULATE (
DISTINCTCOUNT ( 'Members'[pkey] ),
FILTER (
'Members',
YEAR ( 'Members'[StartDate] ) <= _selyear
&& YEAR ( 'Members'[EndDate] ) >= _selyear
)
)
Best Regards
- mayurwadhwani5 years agoHelper I
Thanks Anonymous for the response. But if we keep card visual and show total members irrespective of year. And if we select multiple year from slicer, it shows incorrect value. As SELECTEDVALUE function results blank with multiple selection of year slicer.
Tried to solve this using VALUES function but no luck.Can we achieve this using DAX?
Thanks
- Anonymous5 years agoNot applicable
Hi mayurwadhwani ,
I created a sample pbix file(see attachment) for you, please check whether that is what you want.
Best Regards
- mayurwadhwani5 years agoHelper I
Hi Anonymous ,
If we select all the year in slicer it should show as 8 distinct key. In pbix, its coming out to be 4. Its due to SELECTEDVALUE function. As multiple selection is returning blank.
Thanks