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

Microsoft is giving away 50,000 FREE Microsoft Certification exam vouchers. Get Fabric certified for FREE! Learn more

Reply
JonnyOh
Regular Visitor

Default Selection in Bar Chart

Hello,

 

I have two bar charts (SectorReturns on left and ReturnAttribution on right in image below) that are to be filtered by sector (materials, industrials, consumer disc., etc.).

Screenshot 2021-09-22 083138.png

 

 

 

 

 

 

 

 

 

 

 

 

I have the filtering in place however, I want the ReturnAttribution bar chart to default to the "portfolio" sector and not show the overall attribution by sector. For example for Materials below the filtering for each sector is in place but when nothing is selected in the SectorReturns bar chart, I want the same thing as below to show for the "portfolio" sector. 

Screenshot 2021-09-22 083515.png

 

Additionally, having a data label issue where I don't want the materials label to show in the y-axis for the ReturnAttribution chart. Each bar represents Excess Return, Style, Industry and Selection Effect. I want these labels to show. Table is set up like this:

Screenshot 2021-09-22 083834.png

 

Thanks!

1 ACCEPTED SOLUTION
v-chenwuz-msft
Community Support
Community Support

Hi @JonnyOh 

 

My approach is through measures.

First you have to create 4 measures instead of 4 columns to get a dynamic display.

The 4 measures are basically the same, except that the referenced columns are different.

before you do this, create a table with this formula

Table 2 = VALUES('Table'[Sector])

 

4 measure:

M Excess Return =
VAR _selected =
    CALCULATE (
        SUM ( 'Table'[Excess Retrun] ),
        FILTER ( 'Table', [Sector] = SELECTEDVALUE ( 'Table 2'[Sector] ) )
    )
VAR _no_selected =
    CALCULATE (
        SUM ( 'Table'[Excess Retrun] ),
        FILTER ( 'Table', [Sector] = "Portfolio" )
    )
VAR _IFselected =
    MAX ( 'Table 2'[Sector] ) = SELECTEDVALUE ( 'Table'[Sector] )
RETURN
    IF (
        _IFselected,
        _selected,
        IF ( MAX ( 'Table 2'[Sector] ) = "Portfolio", _no_selected, BLANK () )
    )

MIndustry =
VAR _selected =
    CALCULATE (
        SUM ( 'Table'[Industry] ),
        FILTER ( 'Table', [Sector] = SELECTEDVALUE ( 'Table'[Sector] ) )
    )
VAR _no_selected =
    CALCULATE (
        SUM ( 'Table'[Industry] ),
        FILTER ( 'Table', [Sector] = "Portfolio" )
    )
VAR _IFselected =
    MAX ( 'Table 2'[Sector] ) = SELECTEDVALUE ( 'Table'[Sector] )
RETURN
    IF (
        _IFselected,
        _selected,
        IF ( MAX ( 'Table 2'[Sector] ) = "Portfolio", _no_selected, BLANK () )
    )

MSelection =
VAR _selected =
    CALCULATE (
        SUM ( 'Table'[Selection] ),
        FILTER ( 'Table', [Sector] = SELECTEDVALUE ( 'Table'[Sector] ) )
    )
VAR _no_selected =
    CALCULATE (
        SUM ( 'Table'[Selection] ),
        FILTER ( 'Table', [Sector] = "Portfolio" )
    )
VAR _IFselected =
    MAX ( 'Table 2'[Sector] ) = SELECTEDVALUE ( 'Table'[Sector] )
RETURN
    IF (
        _IFselected,
        _selected,
        IF ( MAX ( 'Table 2'[Sector] ) = "Portfolio", _no_selected, BLANK () )
    )

MStyle =
VAR _selected =
    CALCULATE (
        SUM ( 'Table'[Style] ),
        FILTER ( 'Table', [Sector] = SELECTEDVALUE ( 'Table'[Sector] ) )
    )
VAR _no_selected =
    CALCULATE ( SUM ( 'Table'[Style] ), FILTER ( 'Table', [Sector] = "Portfolio" ) )
VAR _IFselected =
    MAX ( 'Table 2'[Sector] ) = SELECTEDVALUE ( 'Table'[Sector] )
RETURN
    IF (
        _IFselected,
        _selected,
        IF ( MAX ( 'Table 2'[Sector] ) = "Portfolio", _no_selected, BLANK () )
    )

 

After this, do filter via the slicer visual.

Here is my pbix file you can reference.

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
v-chenwuz-msft
Community Support
Community Support

Hi @JonnyOh 

 

My approach is through measures.

First you have to create 4 measures instead of 4 columns to get a dynamic display.

The 4 measures are basically the same, except that the referenced columns are different.

before you do this, create a table with this formula

Table 2 = VALUES('Table'[Sector])

 

4 measure:

M Excess Return =
VAR _selected =
    CALCULATE (
        SUM ( 'Table'[Excess Retrun] ),
        FILTER ( 'Table', [Sector] = SELECTEDVALUE ( 'Table 2'[Sector] ) )
    )
VAR _no_selected =
    CALCULATE (
        SUM ( 'Table'[Excess Retrun] ),
        FILTER ( 'Table', [Sector] = "Portfolio" )
    )
VAR _IFselected =
    MAX ( 'Table 2'[Sector] ) = SELECTEDVALUE ( 'Table'[Sector] )
RETURN
    IF (
        _IFselected,
        _selected,
        IF ( MAX ( 'Table 2'[Sector] ) = "Portfolio", _no_selected, BLANK () )
    )

MIndustry =
VAR _selected =
    CALCULATE (
        SUM ( 'Table'[Industry] ),
        FILTER ( 'Table', [Sector] = SELECTEDVALUE ( 'Table'[Sector] ) )
    )
VAR _no_selected =
    CALCULATE (
        SUM ( 'Table'[Industry] ),
        FILTER ( 'Table', [Sector] = "Portfolio" )
    )
VAR _IFselected =
    MAX ( 'Table 2'[Sector] ) = SELECTEDVALUE ( 'Table'[Sector] )
RETURN
    IF (
        _IFselected,
        _selected,
        IF ( MAX ( 'Table 2'[Sector] ) = "Portfolio", _no_selected, BLANK () )
    )

MSelection =
VAR _selected =
    CALCULATE (
        SUM ( 'Table'[Selection] ),
        FILTER ( 'Table', [Sector] = SELECTEDVALUE ( 'Table'[Sector] ) )
    )
VAR _no_selected =
    CALCULATE (
        SUM ( 'Table'[Selection] ),
        FILTER ( 'Table', [Sector] = "Portfolio" )
    )
VAR _IFselected =
    MAX ( 'Table 2'[Sector] ) = SELECTEDVALUE ( 'Table'[Sector] )
RETURN
    IF (
        _IFselected,
        _selected,
        IF ( MAX ( 'Table 2'[Sector] ) = "Portfolio", _no_selected, BLANK () )
    )

MStyle =
VAR _selected =
    CALCULATE (
        SUM ( 'Table'[Style] ),
        FILTER ( 'Table', [Sector] = SELECTEDVALUE ( 'Table'[Sector] ) )
    )
VAR _no_selected =
    CALCULATE ( SUM ( 'Table'[Style] ), FILTER ( 'Table', [Sector] = "Portfolio" ) )
VAR _IFselected =
    MAX ( 'Table 2'[Sector] ) = SELECTEDVALUE ( 'Table'[Sector] )
RETURN
    IF (
        _IFselected,
        _selected,
        IF ( MAX ( 'Table 2'[Sector] ) = "Portfolio", _no_selected, BLANK () )
    )

 

After this, do filter via the slicer visual.

Here is my pbix file you can reference.

 

Best Regards

Community Support Team _ chenwu zhu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors