Forum Discussion

EaglesTony's avatar
EaglesTony
Icon for Post Prodigy rankPost Prodigy
2 years ago
Solved

How 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
  • EaglesTony 

    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's avatar
    Daniel29195
    Icon for Community Champion rankCommunity Champion

    EaglesTony 

    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's avatar
      EaglesTony
      Icon for Post Prodigy rankPost Prodigy

      For some reason this isn't quite working:

       

       FILTER(
                          MergeFinal,
                          MergeFinal[OnlyFeatures.FeatureParent(SolutionEpicKey)] = varCurrentID
       
      MergeFinal[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 ???