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
mba
Frequent Visitor

Filtered categorical measure yields incorrect output

Hi!

I calculated a measure that first ranks companies based on the revenue generated, then splits them into Tiers (top 25% etc.). Further, I created a complementary measure that allows to filter the desired table based on this measure. Of course, to make it happen, I had to create a intermediary table specifically for this reason. However, it doesn't yield correct results in the end.

Let's start with a data as follows:

 

Company NameGross Revenue

Company A

100 000
Company B80 000
Company C70 000
Company D60 000


The measure that groups into tiers based on revenue is defined as:

 

 

 

Company Tier Group (Based on Gross Revenue) = 

VAR CompaniesCount = CALCULATE(DISTINCTCOUNT(Products[CompanyName]), ALLSELECTED(Products))
VAR RANKING = RANKX
(
    ALLSELECTED(Products),
    CALCULATE
    (
        [Company Revenue (incl. VAT)],
        ALLEXCEPT
        (
            Products,
            Products[CompanyName], 
            Products[Country] // later filtering purposes
        )
    ),
    ,
    DESC,
    Dense
)

VAR TopPercentage = DIVIDE(RANKING, CompaniesCount)

RETURN
IF(ISINSCOPE(Products[CompanyName]),
    IF
    (
        TopPercentage <= 0.25,
        "Tier 1",
        IF
        (
            TopPercentage > 0.25 && TopPercentage <= 0.75,
            "Tier 2",
            "Tier 3"
        )
    )
)

 

 

 

 

and in the table, it works just fine:

Company NameGross RevenueGroup (Based on Revenue)

Company A

100 000Tier 1
Company B80 000Tier 2
Company C70 000Tier 2
Company D60 000Tier 3

 

 

Normally, as in the table shown above, the groups seem to work just fine. To allow using the slicer based on this measure, I had to create an intermediary table (called 'Company Tier List') with just "Tier 1", "Tier 2" and "Tier 3" values next to the other column stipulating its order (to appear nicely in the slicer). The new measure created to allow filtering is defined as follows:

That table:

TIERSORDER
Tier 11
Tier 22
Tier 33


Measure:

 

 

 

Company Tier Group (Based on Gross Revenue) FILTER = 

VAR selectedTier = VALUES('Company Tier List'[Tier])
VAR currentTier = [Company Tier Group (Based on Gross Revenue)]

RETURN 
IF(currentTier IN selectedTier, 1, 0)

 

 

 

... and it worked just fine as well. Putting it all together, I have a table that goes: (no Tier selected in the slicer)

Company NameGross RevenueGroup (Based on Revenue)Group Filter

Company A

100 000Tier 11
Company B80 000Tier 21
Company C70 000Tier 21
Company D60 000Tier 31

 

If I select "Tier 2" on the slicer, I get:

 

Company NameGross RevenueGroup (Based on Revenue)Group Filter

Company A

100 000Tier 10
Company B80 000Tier 21
Company C70 000Tier 21
Company D60 000Tier 30

 

Then, if I want to display only these rows with value of 1 in "Group Filter", I add the visual filter to do so. What I expect is:

Company NameGross RevenueGroup (Based on Revenue)Group Filter
Company B80 000Tier 21
Company C70 000Tier 21

 

What I actually get either an empty table or rows that have inconsistent Tiers.

If I do not impose that filter, I can see that either the Tier 1/2/3 and Group Filter 1/0 marks the rows correctly, also when I impose additional filters of time period and country. It is at the point when I need to show only these with Group Filter equal to 1 when it breaks. It shows more than it should for Tier 1 (that is more than 25% of rows) while putting the rest to Tier 2 and having no rows in Tier 3. It also depends on the number of rows in the period selected. If there are few of them, only filtering for Tier 1 shows all rows, whereas Tier 2 and Tier 3 shows none.

Here are some screenshots that visualise the steps, respectively:

mba_0-1674069713237.png

... using slicer...

mba_1-1674069995235.png

... after using the visual filter...

mba_2-1674070034941.png
I will appreciate any solution to my problem as well as some other suggestions how the desired output may be reached.

 

6 REPLIES 6
Ashish_Mathur
Super User
Super User

Hi,

I cannot understand the logic for the calculated of tiers in the first screenshot.  Company A's revenue is 33% of the total revenue which is >25%.  Why then does it fall in tier 1?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi @Ashish_Mathur ,

It's not about the percentage of a total, but about its rank divided by a number of companies. In case of Company A, it's ranked 1 out of 4, what yields 1/4 = 0.25 = 25%.

To allow using the slicer based on this measure

You cannot base slicers on measures. Best you can do is use what-if parameters.

Hi,

I cannot get your expected result.  However, you may refer to my measure in this PBI file and tweak the measures.  Sorry but could not help.

Untitled.png 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Greg_Deckler
Super User
Super User

@mba Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler ,

Thank you for the response and suggestions! I tried to make the issue more transparent via editing the initial post. I hope it is more clear to you now.

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.