Forum Discussion

agd50's avatar
agd50
Helper V
3 years ago
Solved

Filter (DistinctCount) - DAX Newbie


Hey forum,
I want to be able to create a measure that aggregates as a DistinctCount but only shows the value for the current year (including if I check in a year from now).

Please Help, Thanks

(censored for privacy reasons)

  • Hello agd50 ,

    you can use below calculation to achieve this:

    Calculate(DistinctCount(Column), filter(Table, Year(Table[Date])= Year(Today())))

     

    If this post helps, then please consider accepting it as the solution to help other members find it more quickly. Thank You!!

4 Replies

  • Hello agd50 ,

    you can use below calculation to achieve this:

    Calculate(DistinctCount(Column), filter(Table, Year(Table[Date])= Year(Today())))

     

    If this post helps, then please consider accepting it as the solution to help other members find it more quickly. Thank You!!

    • agd50's avatar
      agd50
      Helper V

      I agree thanks, but I assume that calculate is not neccessary in measures as that is already automatically included

      • agd50's avatar
        agd50
        Helper V

        On second thought this may not work for me as I forgot to mention dim_calendar is a separate table to the aggregation so I assume that a related/relatedtable which need to be included somewhere

  • Count of x YTD =
        CALCULATE (
            DISTINCTCOUNT ( 'x'[x] ),

            FILTER (RELATEDTABLE(Dim_Calendar), YEAR(Dim_Calendar[Date])=YEAR(TODAY()
            )
        )
    )

    This worked exactly how I wanted it to, Thanks