Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Percentage of occurence in filtered rows

Hi,

 

I'm trying to display in a table 4 rows containing :

 

  1. The UserAgent responsible for the hit on my website
  2. The number of times this UserAgent created a hit (i.e. the number of rows in which it appears)
  3. The percentage of hits attributed to this UserAgent globally
  4. The percentage of hits attributed to this UserAgent among the other UserAgents that have not been filtered out

I have other visualizations on my report that allow me to filter out some UserAgents.

Here are my calculated measures and columns :

Measures :

  • TotalHits = CALCULATE(COUNTROWS('hits-store');ALL('hits-store'))
  • Tot = CALCULATE(COUNTROWS('hits-store');ALLSELECTED('hits-store'))

Columns :

  • Global = 1/[TotalHits]
  • Filtered = 1/[Tot]

I have the expected results when I don't filter anything :

Data without any filtersData without any filters

 

But when I filter out some UserAgents, the Filtered and Global columns return the same results !

(the Filtered column for the first UserAgent should display 8,6%, and should add up to 100%) :

Data with filtersData with filters

I even tried to display my Tot and TotalHits measures to see if they were wrong :

totpbi.PNG

They are not.

 

I'm not a DAX expert, am I missing something here ?

8 REPLIES 8
chrisu
Responsive Resident
Responsive Resident

I think this has something to do with how ALLSELECTED() works.  Have you tried changing your Tot calculate filter to ALLSELECTED(UserAgent)?

 

More information at http://www.sqlbi.com/articles/understanding-allselected/

Anonymous
Not applicable

Hi chrisu, thanks for taking the time.

 

I tried your solution, but it doesn't change a thing.

I've tried various formulas after reading you article, but nothing really seems to work.

I can't seem to be able to keep the filter context of my page using ALLSELECTED() because it is inside a division (which adds one layer of calculation to my table, fuzzing my context filters in my page).

I'm not entirely sure I grasped everything in your article perfectly, so I may be talking nonsense.

Sean
Community Champion
Community Champion

@Anonymous how is you data organized? Can you post an example?

 

Is it like this?

Filtered%.png

 

EDIT: From the above table is this the result you are looking for?

Filtered%2.png

Anonymous
Not applicable

@Sean this is almost exactly what I'm trying to accomplish. The results you have are what I want.

Except my UserAgents are filtered out by another Table (called references) that contains the names of the UserAgents I want to filter out.

context.PNG

I have only one relationship in my model.

This is the filter I use on my report, which displays the values of 'references'[Column1.Name] :

filter.PNG

 

I probably should have mentioned that earlier ...

 

@Anonymous

 

If you have built the relationship between User Agent and reference name, you can just build two slicers in your report. The User Agent will be cascaded based on the reference name selection. Then you can just COUNTROWS() the 'hits-store' divide by ALL() and ALLSELECTED() calculation.

 

Measures:

Hits = CALCULATE(COUNTROWS('hits-store')
TotalHits = CALCULATE(COUNTROWS('hits-store'),ALL('hits-store'​))
Tot = CALCULATE(COUNTROWS('hits-store'),ALLSELECTED('hit​s-store'))
Filtered = [Hits]/[TotalHits]
Global = [Hits]/[Tot]

 

 

Anonymous
Not applicable

 Hi @v-sihou-msft,

 

I have tried to use all the measures you recommended but it gives me an error when I try to input the last formula :

 

error.PNG

 

I'm not quite sure what exactly you meant by having two slicers (I don't get what is the point ?) but here is a screenshot of the whole report :

whole pbix.PNG

I can't display Global in the table because the formula is invalid, but "Filtered" doesn't return the expected value.

@Anonymous

 

The error message indicates that the [Global] and [Filtered] has referenced each other so that it will detect circular dependency. Please check the expression in [Filtered].

 

The two slicers means one slicer for UserAgent selection, the other slicer for referenced name. When you select in reference name slicer, the UserAgent will be cascaded(selected automatically).

 

Regards,

Anonymous
Not applicable

Hi @v-sihou-msft,

 

I have in my file :

Hits = CALCULATE(COUNTROWS('hits-store'))

TotalHits = CALCULATE(COUNTROWS('hits-store');ALL('hits-store'))

Tot = CALCULATE(COUNTROWS('hits-store');ALLSELECTED('hits-store'))

Filtered = [Hits]/[TotalHits]

Global = [Hits]/[Tot]

 

If I'm not mistaken Global and Filtered do not reference each other in those formulas. This might be some kind of weird behaviour of DAX ?

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.