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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
jslade
Helper I
Helper I

Removing Blank Row from Top N With Field Parameter

I'm using Field Parameters to allow a user to pick the column they want to see a top 5 in a Clusted Bar Chart.  
I created a RankX function with a SWITCH funciton that will allow me to filter the top 5, but it is including blanks in the Field Parameter.  How can I exclude the blank from the rankx function?  Below is my dax for the measure and a screenshot of what is happening

 

Stat Area Rank By Res = SWITCH(
TRUE(),
SELECTEDVALUE('Statistical Area'[Statistical Area Fields])="'DimCustomer'[CBSA]",
RANKX(ALLNOBLANKROW(DimCustomer[CBSA]), FactReservation[Reservations],,DESC),
SELECTEDVALUE('Statistical Area'[Statistical Area Fields])="'DimCustomer'[CSA]",
RANKX(ALLNOBLANKROW(DimCustomer[CSA]), FactReservation[Reservations],,DESC),
SELECTEDVALUE('Statistical Area'[Statistical Area Fields])="'DimCustomer'[MSA]",
RANKX(ALLNOBLANKROW(DimCustomer[MSA]), FactReservation[Reservations],,DESC))

 

jslade_3-1686332335105.png

 

I was able to filter the (blank) by adding adding a filter to the visual filters, but I'm afraid when the user changes the field parameter slicer it won't filter out based on the change.

 

 

 

2 REPLIES 2
jslade
Helper I
Helper I

Thank you for these. I tried them both, but I am still getting the blank column in my bar charts.  The only way I have been able to filter it out is by adding each of the three DimCustomer fields (MSA, CBSA and CSA) to the visual filter and setting them to 'all except blank.'  This appears to work, but I fear that that if there is a result with MSA but CBSA is blank that it is just filtering that result out when MSA is selected in the field parameter slicer even though the MSA is not blank, because the visual is set to filter out blank CBSAs.

v-jingzhang
Community Support
Community Support

Hi @jslade 

 

You may try this 

Stat Area Rank By Res =
SWITCH (
    TRUE (),
    SELECTEDVALUE ( 'Statistical Area'[Statistical Area Fields] ) = "'DimCustomer'[CBSA]",
        RANKX (
            ALLNOBLANKROW ( DimCustomer[CBSA] ),
            CALCULATE (
                SUM ( FactReservation[Reservations] ),
                FactReservation[CBSA] <> BLANK ()
            ),
            ,
            DESC
        ),
    SELECTEDVALUE ( 'Statistical Area'[Statistical Area Fields] ) = "'DimCustomer'[CSA]",
        RANKX (
            ALLNOBLANKROW ( DimCustomer[CSA] ),
            CALCULATE (
                SUM ( FactReservation[Reservations] ),
                FactReservation[CSA] <> BLANK ()
            ),
            DESC
        ),
    SELECTEDVALUE ( 'Statistical Area'[Statistical Area Fields] ) = "'DimCustomer'[MSA]",
        RANKX (
            ALLNOBLANKROW ( DimCustomer[MSA] ),
            CALCULATE (
                SUM ( FactReservation[Reservations] ),
                FactReservation[MSA] <> BLANK ()
            ),
            DESC
        )
)

Or 

Stat Area Rank By Res =
SWITCH (
    TRUE (),
    SELECTEDVALUE ( 'Statistical Area'[Statistical Area Fields] ) = "'DimCustomer'[CBSA]",
        RANKX (
            FILTER ( ALL ( DimCustomer[CBSA] ), DimCustomer[CBSA] <> BLANK () ),
            FactReservation[Reservations],
            ,
            DESC
        ),
    SELECTEDVALUE ( 'Statistical Area'[Statistical Area Fields] ) = "'DimCustomer'[CSA]",
        RANKX (
            FILTER ( ALL ( DimCustomer[CSA] ), DimCustomer[CSA] <> BLANK () ),
            FactReservation[Reservations],
            ,
            DESC
        ),
    SELECTEDVALUE ( 'Statistical Area'[Statistical Area Fields] ) = "'DimCustomer'[MSA]",
        RANKX (
            FILTER ( ALL ( DimCustomer[MSA] ), DimCustomer[MSA] <> BLANK () ),
            FactReservation[Reservations],
            ,
            DESC
        )
)

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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