Skills Advisor | Data Visualization

Power BI Filtering for NHS Organization Analysis

This guide addresses issues with automated filtering for the NHS Bath And North East Somerset, Swindon And Wiltshire Integrated Care Board in Power BI charts, detailing DAX measure adjustments and best practices for data visualization.


Empty image or helper icon

Prompt

i still dont understand the chart still does no drag automatically to NHS BATH organisation as below, i still need to drag to the organisation on the chart? Opido1_ICB_Combined = 
VAR SelectedOrg = "NHS Bath And North East Somerset, Swindon And Wiltshire Integrated Care Board"
VAR BaseMeasure = SUM(Fact_Opiod1_ICB[Patients receiving opioid pain medicines per 1,000 patients])
VAR TotalMeasure =
    CALCULATE(
        BaseMeasure,
        ALL(DatesCalendar[MonthnYear])
    )
VAR OrgContext =
    UNION(
        FILTER(
            VALUES(Fact_Opiod1_ICB[Prescribing organisation]),
            Fact_Opiod1_ICB[Prescribing organisation] = SelectedOrg
        ),
        FILTER(
            VALUES(Fact_Opiod1_ICB[Prescribing organisation]),
            Fact_Opiod1_ICB[Prescribing organisation] <> SelectedOrg
        )
    )

RETURN
    IF(
        SELECTEDVALUE(Fact_Opiod1_ICB[Prescribing organisation]) IN OrgContext,
        CALCULATE(BaseMeasure, OrgContext),
        TotalMeasure
    )

Answer

Data Visualization Context in Power BI

Problem Overview

Your issue relates to a Power BI chart not automatically filtering data for the specific "NHS Bath And North East Somerset, Swindon And Wiltshire Integrated Care Board". You need to drag this specific organization to the chart, which indicates a problem with how context and filters are managed in your DAX measure.

DAX Measure Breakdown

Let’s analyze your DAX code to understand its behavior:

Code Review

Opido1_ICB_Combined = 
VAR SelectedOrg = "NHS Bath And North East Somerset, Swindon And Wiltshire Integrated Care Board"
VAR BaseMeasure = SUM(Fact_Opiod1_ICB[Patients receiving opioid pain medicines per 1,000 patients])
VAR TotalMeasure =
    CALCULATE(
        BaseMeasure,
        ALL(DatesCalendar[MonthnYear])
    )
VAR OrgContext =
    UNION(
        FILTER(
            VALUES(Fact_Opiod1_ICB[Prescribing organisation]),
            Fact_Opiod1_ICB[Prescribing organisation] = SelectedOrg
        ),
        FILTER(
            VALUES(Fact_Opiod1_ICB[Prescribing organisation]),
            Fact_Opiod1_ICB[Prescribing organisation] <> SelectedOrg
        )
    )

RETURN
    IF(
        SELECTEDVALUE(Fact_Opiod1_ICB[Prescribing organisation]) IN OrgContext,
        CALCULATE(BaseMeasure, OrgContext),
        TotalMeasure
    )

Key Components

  1. SelectedOrg: Represents the specific organization you're filtering for.
  2. BaseMeasure: Calculates the sum of patients receiving opioid pain medicines per 1,000 patients.
  3. TotalMeasure: Provides a total across all months using ALL.
  4. OrgContext: Creates a union of organizations that either include or exclude the selected one.
  5. IF Statement: Checks if the current selected organization (SELECTEDVALUE) is part of the OrgContext. If it is, it calculates BaseMeasure with that context; otherwise, it returns the TotalMeasure.

Recommendations

Automatic Filtering

  1. Modify Context: Adjust your measure to directly filter based on the selected organization without needing manual interactions. You can use the following approach:

    Opido1_ICB_Combined = 
    VAR SelectedOrg = "NHS Bath And North East Somerset, Swindon And Wiltshire Integrated Care Board"
    VAR BaseMeasure = SUM(Fact_Opiod1_ICB[Patients receiving opioid pain medicines per 1,000 patients])
    
    RETURN
        CALCULATE(
            BaseMeasure, 
            Fact_Opiod1_ICB[Prescribing organisation] = SelectedOrg
        )
  2. Slicer Usage: Ensure you have a slicer in your report that allows you to filter by the "Prescribing organisation". This will provide better interaction, and when you select "NHS Bath...", your chart should automatically update.

  3. Visual Level Filters: Implement visual-level filters on your chart to always filter by the organization without needing to drag it into the visual. Set this up in the filter pane for your chart.


Best Practices

  • Organize Measures: Create measures that are simple and have a single responsibility to avoid complexity.
  • Test Incremental Changes: After modifying your DAX logic, check the output to ensure behavior aligns with expectations.
  • Use Tooltips and Labels: To improve the understanding of your charts, use tooltips and labels effectively to indicate what data is being displayed.

Additional Learning

For a deeper understanding of DAX and Data Visualization, consider courses available on the Enterprise DNA Platform. These resources can help you refine your skills and enhance your data analysis capabilities.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This guide addresses issues with automated filtering for the NHS Bath And North East Somerset, Swindon And Wiltshire Integrated Care Board in Power BI charts, detailing DAX measure adjustments and best practices for data visualization.