Forum Discussion
How to make distinct count value with filter as constant
- 4 years ago
Hey Georgia_H ,
I changed the denominator and the division measure in my example. Please be aware that I only used two metrics inside both measures to create a virtual table.The denominator now is more or less a constant:
denominator = var metricsToCount = {"PCM01" , "PCM23"} var metricsCount = COUNTROWS( metricsToCount ) return metricsCountYou might expand the definition of the denominator like so
denominator check = var metricsToCount = {"PCM01" , "PCM23"} var metricsCount = COUNTROWS( metricsToCount ) return IF( FIRSTNONBLANK( 'Table'[Metrics_ID] , 'Table'[Metrics_ID] ) in metricsToCount , metricsCount , BLANK() )
The division measure now looks like this:division = var metricsToCount = {"PCM01" , "PCM23"} var metricsCount = COUNTROWS( metricsToCount ) return AVERAGEX( 'Table' , if( FIRSTNONBLANK( 'Table'[Metrics_ID] , 'Table'[Metrics_ID] ) in metricsToCount , DIVIDE( 'Table'[Avg Compliance %] , metricsCount ) , BLANK() ) ) * 100The table visual looks like this:
Of course, it's possible to create a table from the 12 metrics, then you do not have to repeat the definition in both measures, but if they are just used in two measures I would probably use the measure definition.
As the metric is used inside your table, it will contribute to the current filter context, but the current filter context will not be expanded, for this reason the DISTINCTCOUNT will return 1.
Hopefully, this will help to tackle your challengeRegards,
Tom
Hey Georgia_H ,
maybe these two measures provide what you are looking for:
denominator (basically a distinctcount of the metrics_id column, with ALL (the table) )
denominator =
CALCULATE(
DISTINCTCOUNT( 'Table'[Metrics_ID] )
, ALL( 'Table' )
)
And the division ( this one is more complex as I'm using the table iterator function AVERAGEX to calculate the average after the division)
division =
AVERAGEX(
'Table'
, DIVIDE( 'Table'[Avg Compliance %] , [denominator] )
) * 100
This allows to create a table visual like the one below:
Regards,
Tom
- Georgia_H4 years ago
Helper I
HI TomMartens
Thanks for the quick response. The issue is for those with multiple rows like PAMC in my data set, if you select on PAMC, it will still show as 1 on each row, instead of 12 on every row. That is the issue i am facing. Also, i have a filter on certain metrics_ID for my denominator.
My expected result should be:
Expected Results for PAMC LBU Metrics_ID Avg Compliance % Denominator (unique by Metrics_ID) Expected Compliance_Value (AVG) divided by MAX Count of Denominator i.e. 12 PAMC PCM01 78.80% 12 6.57% PAMC PCM03 81.30% 12 6.78% PAMC PCM04 62.10% 12 5.18% PAMC PCM09 56.80% 12 4.73% PAMC PCM10 59.60% 12 4.97% PAMC PCM19 68.60% 12 5.72% PAMC PCM20 55.90% 12 4.66% PAMC PCM23 85.90% 12 7.16% PAMC PCM33 65.00% 12 5.42% PAMC PCM34 47.80% 12 3.98% PAMC PCM35 57.10% 12 4.76% PAMC PCM36 62.00% 12 5.17% - TomMartens4 years ago
Super User
Hey Georgia_H ,
this is how my data looks:
Here you will find my pbix https://tommartens-my.sharepoint.com/:u:/g/personal/tom_minceddata_com/EUMsIS3jsJBAt6dpaI5hngsB9wwHOw-uB_te1NTATIERhA?e=8thQGY
Regards,Tom
- Georgia_H4 years ago
Helper I
Hi Tom,
I tested the concept in my real dataset.
My real dataset has more than 12 Metrics_ID, however i only need to count on 12 Metrics_ID, hence my measure is written like:
ALCULATE(DISTINCTCOUNT('rep F_ITS_MetricsLanding'[Metrics_ID]),FILTER('rep F_ITS_MetricsLanding','rep F_ITS_MetricsLanding'[Metrics_ID] in {"PCM01","PCM03","PCM04","PCM09","PCM10","PCM19","PCM20","PCM23","PCM33","PCM34","PCM35","PCM36"}),ALL('rep F_ITS_MetricsLanding'[Metrics_ID]))
I dont get the same results as yours (12 on every row). I still get 1 on the relevant rows. What could be wrong with my DAX syntax?