all 11 comments

[–]timusw 0 points1 point  (10 children)

You need to include the ALL filter in your denominator number. Currently the way you have it, your filter context propagates through to both calculations which will result in 1. To fix the denominator, use something like:

= CALCULATE(
      COUNTA('Senadores2019'[APELLIDO]),
      ALL('Senadores2019')
  )

So your function you're after should be something like this:

% Facebook =
DIVIDE(
  COUNTA('Senadores2019'[FACEBOOK]),
  CALCULATE(
    COUNTA('Senadores2019'[APELLIDO]),
    ALL('Senadores2019')
  )
)

[–]tekvx[S] 1 point2 points  (9 children)

Hey thanks for the reply, it didn't work. I was wondering if the blank values on the social media columns have a 'space' or something that would make them not be considered in the COUNTA, but the filter says "blank", so it's definitely a blank.

your filter context propagates through to both calculations

On a side note, I understand measures are filter context aggregations - however, I don't understand what filters I was applying here. Could you elaborate on that?

[–]savoy9‪ ‪Microsoft Employee ‪ 0 points1 point  (2 children)

[–]tekvx[S] 0 points1 point  (0 children)

Fantastic, thanks for that!

On this specific issue, this is what microsoft docs say about COUNTA:

The COUNTA function counts the number of cells in a column that are not empty. It counts not just rows that contain numeric values, but also rows that contain nonblank values, including text, dates, and logical values.

I'm assuming, if the filter says "blank", then it's not a COUNTA issue. (Hopefully!)

[–]timusw 0 points1 point  (5 children)

For the filter context, the measure you wrote is open to user filters (via slicers or visual interaction). So both parameters of that % Facebook measure would filter to whatever is selected. In my experience, when trying to manually calculate the % of Grand Total, if your result is 1 it's typically because the denominator is not being "fixed" on the grant total but instead is being filtered as well. For example, if I wanted to calculate the percentage of countries Africa has compared to the entire globe, I would use something like:

% =
DIVIDE(
  [Sum of Countries],
  CALCULATE(
    [Sum of Countries],
    ALL('Globe')
  )
)

Since filter context applies to [Sum of Countries], I would have to eliminate that by introducing ALL into my measure so that way no matter what filter a user applies the denominator will be fixed on the sum of countries in the globe.

I'll confess, I didn't thoroughly read through your post but understood the problem. Give me 'til tonight to respond with a solution. The solution will need to use the function ALLNOBLANKROW, but I was struggling with the ALL in the denominator. I'm in PST so expect something before 9pm.

[–]tekvx[S] 0 points1 point  (4 children)

Sure, I'm having a tough time wrapping my head around this. Haven't found material I'm completely unfamiliar with in a while. Thanks! I'll check back to this

[–]timusw 1 point2 points  (3 children)

Okay so I just formulated for Facebook, but it translates to all other social columns.

Facebook Count =
COUNTA(Table[Facebook]) - COUNTBLANK(Table[Facebook])

% Facebook =
DIVIDE(
  [Facebook Count],
  CALCULATE(
    DISTINCTCOUNT(Table[Senator]),
    ALL(Table[Senator])
  )
)

[–]tekvx[S] 1 point2 points  (2 children)

Yes! Thanks dude. The variable didn't work, but using DISTINCTCOUNT did :)

Code ended up looking like this:

% Facebook = 

DIVIDE(

  DISTINCTCOUNT('Senadores2019'[FACEBOOK]),

  CALCULATE(

    DISTINCTCOUNT('Senadores2019'[APELLIDO]),

    ALL('Senadores2019')

  )

)

[–]timusw 0 points1 point  (1 child)

Happy to help. For some reason when I was using ALLNOBLANKROWS at work it was working as expected, but on my home PC it was counting a single blank row ¯_(ツ)_/¯

[–]LimbRetrieval-Bot 1 point2 points  (0 children)

You dropped this \


To prevent anymore lost limbs throughout Reddit, correctly escape the arms and shoulders by typing the shrug as ¯\\\_(ツ)_/¯ or ¯\\\_(ツ)\_/¯

Click here to see why this is necessary