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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
seniorathlete
Regular Visitor

Dynamic Top 10 - Using Parameter to Keep/Exclude Value

Hello All,

I'm trying to create a visual that shows the top 10 conditions by counts per year that also has a parameter that allows me to include COVID-19 or not. Since COVID-19 case counts are so large, it dwarfs/masks the trends in the other condition. Basically I want to have a parameter that is yes/no - yes includes COVID-19 in the top 10 rankings, or no exclude COVID-19 from the top 10 rankings. And In my rankings I always want to have 10 conditions.

 

Fake data:

 

yeardiseasecases
2020COVID-191
2020influenza5
2020measles1
2021COVID-195
2021influenza2
2021measles1
2022COVID-1910
2022influenza5
2022measles3
2023COVID-194
2023influenza10
2023measles5

 

3 REPLIES 3
Anonymous
Not applicable

Hi DataNinja777 ,thanks for the quick reply, I'll add more.

Hi @seniorathlete ,

Parameter-like effects can be achieved using a slicer.

Please follow these steps:

1.Create 'Table 2' by manually entering the following data

vzhouwenmsft_0-1737340676221.png

2.Use the following DAX expression to create measures

 

TotalCases = 
VAR _includeCovid19 = SELECTEDVALUE('Table 2'[IncludeCovid19])
RETURN
IF(_includeCovid19 = "Yes",
    SUMX('Table',[cases]),IF(_includeCovid19 = "No",SUMX(FILTER('Table',[disease] <> "COVID-19"),[cases]))
)
Top10 = 
IF(ISBLANK([TotalCases]),BLANK(),RANKX(ALLEXCEPT('Table','Table'[year]),[TotalCases],,DESC,Dense))

 

3.Make the measure “Top10” available in the filter pane and set it to less than or equal to 10.

vzhouwenmsft_1-1737340886473.png

4.Use the following DAX expression to create a measure

 

Measure = (SELECTEDVALUE('Table'[year]) * 100 + [Top10]) * -1

 

Turn off the following options and add the measure to the visual 

vzhouwenmsft_3-1737341677263.png

Place the mouse over the marker position, the “<-||->” symbol will appear and drag it to the left

vzhouwenmsft_4-1737341742103.png

Final output

vzhouwenmsft_5-1737341864053.png

 

 

DataNinja777
Super User
Super User

Hi @seniorathlete ,

 

To create a visual that dynamically displays the top 10 conditions by case counts per year while allowing the inclusion or exclusion of COVID-19, you can use a combination of a parameter and DAX measures in Power BI.

First, create a parameter named Include COVID-19 with two options: "Yes" and "No." This parameter will allow users to toggle whether COVID-19 is included in the rankings. Once the parameter is created, it can be added as a slicer in the report to provide interactivity.

Next, define a DAX measure to calculate the top 10 conditions dynamically based on the parameter value. The measure should filter the dataset to exclude COVID-19 when the parameter is set to "No" while still ensuring that the top 10 conditions are displayed for each year.

Top 10 Conditions = 
VAR IncludeCOVID = SELECTEDVALUE('Include COVID-19'[Include COVID-19])
VAR FilteredTable =
    IF(
        IncludeCOVID = "Yes",
        'Disease Data',
        FILTER('Disease Data', 'Disease Data'[disease] <> "COVID-19")
    )
VAR RankedConditions =
    ADDCOLUMNS(
        SUMMARIZE(
            FilteredTable,
            'Disease Data'[year],
            'Disease Data'[disease]
        ),
        "@TotalCases", SUM('Disease Data'[cases])
    )
VAR Top10 =
    TOPN(10, RankedConditions, [@TotalCases], DESC)
RETURN
    Top10

The measure begins by checking the selected value of the parameter. If the parameter is set to "Yes," the entire dataset is used. If the parameter is set to "No," the dataset is filtered to exclude rows where the disease is "COVID-19." The SUMMARIZE function is then used to group the data by year and disease, calculating the total cases for each combination. The TOPN function is applied to extract the top 10 conditions based on the total cases in descending order.

To visualize the data, use a table or matrix visual in Power BI. Add the year and disease columns as rows and the cases column as values. Apply the Top 10 Conditions measure as a filter on the visual, ensuring only the top 10 conditions are displayed for each year. Place the parameter slicer on the report to allow users to toggle the inclusion of COVID-19 dynamically.

When the parameter is set to "Yes," COVID-19 will appear in the top 10 conditions if its case count qualifies. When the parameter is set to "No," COVID-19 will be excluded, and the next top-ranking condition will replace it, ensuring that the visual always displays 10 conditions per year. This approach provides flexibility in analyzing the trends of other conditions without the overwhelming dominance of COVID-19 case counts.

 

Best regards,

Thanks for the response. Using this solution I get the "expression refers to multiple columns. multiple columns cannot converted to a scalar value" error message.

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors