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
fabo
Advocate III
Advocate III

Conditional Top 20

Hi everyone. 

 

I have this scenario: 219 plants ("Production Unit" or "PU") are located in 15 geographical regions. They produce only one product in different amounts. Data is collected monthly. Visually:

 

original1.PNG

 

 The data model is the following:

 

data_model.PNG

 

What I need to do is a "PU" Top 20 (Plant Top 20) in chart 2 (chart in the right side) only if there is no Region selected in chart 1 (chart in the left side).  If there is at least one Region selected, then chart 2 is simply filtered by that Region showing only the plants located there.

 

original2.PNG

 

What I did

 

I added a calculated column in plant table (T_PU) named Rank:

 

Rank =

RANKX(

 ALL(T_PU);

 CALCULATE([Sum of Production])

)

 

And these measures:

 

Sum of Production = SUM(FT_Production[Production])

 

Production by PU =

IF(

 [No of Selected Regions] <> [No of Total Regions];

//This is True when at least one region is selected

 CALCULATE([Sum of Production]);  CALCULATE([Production Top 20])

)

 

No of Selected Regions = DISTINCTCOUNT(T_Region[id_region])

 

No of Total Regions =

CALCULATE(  DISTINCTCOUNT(T_Region[id_region]);  ALL(T_Region)

)

 

Production Top 20 =

CALCULATE(

 [Sum of Production];

 T_PU[Rank] <= 20

)

 

What I got...

 

Two issues:

 

1. A quasi-Top 20 chart. 

 

result1.PNG

 

The Top 20 chart seems to be ok but.. The order is not quite right:

 

comparison.PNG

 

2. When a Region is selected the resulting chart only shows some plants (in some regions, it shows no plant at all).

 

result2.PNG

 

Maybe some of my steps are not appropriate. Or maybe I need a complete different approach. Any suggestion will be welcome.

 

 

Regards!

 

Fabo

 

1 ACCEPTED SOLUTION
Vvelarde
Community Champion
Community Champion

@fabo

 

Hi, Please try with this measure:

 

ProductionShow =
IF (
    HASONEVALUE ( T_Region[Region] ),
    [Sum of Production],
    IF (
        COUNTROWS (
            INTERSECT (
                VALUES ( T_PU[Production Unit] ),
                TOPN ( 20, ALLSELECTED ( T_PU[Production Unit] ), [Sum of Production], DESC )
            )
        )
            > 0,
        [Sum of Production],
        BLANK ()
    )
)

ShowTop20OrSelected.gif

 

Regards

 

Victor

Lima - Peru




Lima - Peru

View solution in original post

18 REPLIES 18

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.