Forum Discussion
EaglesTony
Post Prodigy
2 years agoHow do I do a distinct with DAX ?
Hi,
I have the following:
NumberofFeaturesUnderSolutionEpic =
VAR varCurrentID = MergeFinal[OnlyFeatures.FeatureParent(SolutionEpicKey)]
VAR varFeatureCount =
COUNTROWS(
DISTINCT(
SELECTCOLUMNS(
FILTER(
MergeFinal,
MergeFinal[OnlyFeatures.FeatureParent(SolutionEpicKey)] = varCurrentID
),
"@Features", MergeFinal[OnlyFeatures.FeatureKey]
)
)
)
RETURN
varFeatureCount
There are 4 rows that have the same SolutionEpicKey, but I need to use only 1, thus distinct, as my calculation is showing 16 instead of 4.
I'm not sure where to put the DISTINCT and the syntax ????
VAR varCurrentID = DISTINCT(MergeFinal[OnlyFeatures.FeatureParent(SolutionEpicKey)])
OR do I use
FILTER(
MergeFinal,
DISTINCT(MergeFinal[OnlyFeatures.FeatureParent(SolutionEpicKey)]) = varCurrentID
But this syntax seems wrong, as there are 4 records in the table
to get one value :
use max , min ...
VAR varCurrentID = max(MergeFinal[OnlyFeatures.FeatureParent(SolutionEpicKey)])if the MergeFinal[OnlyFeatures.FeatureParent(SolutionEpicKey)] is unique per each filter context, then you have no problem,
hope this helps .
3 Replies
- Daniel29195
Community Champion
to get one value :
use max , min ...
VAR varCurrentID = max(MergeFinal[OnlyFeatures.FeatureParent(SolutionEpicKey)])if the MergeFinal[OnlyFeatures.FeatureParent(SolutionEpicKey)] is unique per each filter context, then you have no problem,
hope this helps .
- EaglesTony
Post Prodigy
For some reason this isn't quite working:
FILTER(MergeFinal,MergeFinal[OnlyFeatures.FeatureParent(SolutionEpicKey)] = varCurrentIDMergeFinal[OnlyFeatures.FeatureParent(SolutionEpicKey) does not have the Key as 64, but for this ID, it is returning 1 instead of 0.I think I need some logic as "WHERE MergeFinal[OnlyFeatures.FeatureKey]) IS NOT NULL ???
- EaglesTony
Post Prodigy
Thank you!