Forum Discussion

chq's avatar
chq
Icon for Helper II rankHelper II
7 years ago
Solved

Apply filter to formula

Is there a way to add a formula filter for a certain year to the following equation? I have tried multiple ways but end up with errors. 

# Count = SUMX( VALUES( 'Table'[Event Title] )  ,CALCULATE(DISTINCTCOUNT( 'Table'[ID#] ) ))

 

5 Replies

  • Cmcmahan's avatar
    Cmcmahan
    Icon for Resident Rockstar rankResident Rockstar

    So this measure reads seems like you're trying to sum the count of distinct table IDs, but only while using the [Event Title] column?? It's like you're asking "How many tables do we have? Sum all those numbers you just told me! Oh, and the only data I'm giving you to work with is the list of Event Titles!" That seems not right to me.  

     

    I would start from scratch and re-write it like this for 2019:

    # Count = CALCULATE( DISTINCTCOUNT('Table'[ID#]), FILTER('Table', YEAR('Table'[Date]) = 2019) )

    Depending on what sort of visual you're putting this in, you may not have to specify all this.  If it's in a column chart with the year as an axis, PowerBI will automatically do this filtering for you if you set up the value of the bar to be a distinct count of IDs. More info on how you're using this and/or table structure would be helpful if this isn't the result you're looking for.

     

    • chq's avatar
      chq
      Icon for Helper II rankHelper II

      Maybe this will help explain what the desired outcome is



      Date      Event Title     # Distinct Count          Week

      1/1/19         A                  50                              1

      1/3/18         B                  75                              1

      7/4/19         X                  99                              4

      7/4/18         V                  10                              4

      TOTAL                              234

      My formula is giving me the # Distinct count correctly, So the above table is fine and already in my report. Below that Table I want to place the following:

      Week      Distinct Count 2018          Distinct Count 2019       Difference               %Change
      1                         75                                      50                             -25                         -33.33%

      4                         10                                      99                              89                           890%


      Does that help?

      • tex628's avatar
        tex628
        Icon for Community Champion rankCommunity Champion

        What do you get if you just apply this:

        Measure =
        Calculate(
        Distinctcount(Table1[ID]),
        Calendar[Year] = "2019"
        )

        From my perspective you shouldnt need anything else with the data provided..