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
eloomis
Advocate II
Advocate II

Data modeling- multiple subcategories in a dimension

I have a matrix visual which has under rows a Sector and then a Subcategory, both in the same dimension table. DimSector looks like this:

SectorSubSectorSector Key
Cash 1
GovernmentU.S. Treasury2
GovernmentAcency/Sovereigns3
CreditCorporate4
CreditMunicipals5
SecuritizedRMBS6

 

I then have a Fact table where I am doing the following DAX calculation. 

 

 

 

# Portfolio % = 
DIVIDE(
    [# Total_Market_Value_Base],
    CALCULATE(
        SUMX(FactPortfolioSectorDetails,[# Total_Market_Value_Base]),
        ALLSELECTED(FactPortfolioSectorDetails)
    )
)

# Total_Market_Value_Base = 
SUMX(FactPortfolioSectorDetails,[Market Value (Base)] + ([Accrued Interest] * [FX to Target]))

 

 

 

 

A scrubbed dataset with for FactPortfolioSectorDetails can be found here: https://docs.google.com/spreadsheets/d/1XIEuyCVwXE7pGR5YToK4S_dT9_prWkpQ/edit?usp=sharing&ouid=11467...

 

This is the visual.

  • Port % is [# Portfolio %] measure.
  • Sector is [Asset Type Subcategory] in FactPorfolioSectorDetails.
  • The subcategories of Sector are [Asset Type] in the fact table.
  • There is a slicer filtering the visual to display a single Account ID.

eloomis_0-1707434169951.png 

eloomis_1-1707434313167.png

 

When Government is minimized, it displays the correct value. When I expand it, it just divides the value for government in half instead of recalculating for each subsector. I need Portfolio % to calculate independently for each subsector grouping, and then calculate for the overall sector grouping. I'm not sure what I have wrong in my model to fix this.

 

I tried splitting Sector and Subsector to different dimension tables and having a key relating to FactPortfolioSectorDetails but this did not work. I also know that I have Sector and Subsector as values in my fact table, but I need to have a sector dimension to use in the visual, as there is another fact table in the schema which also will be supplying fields to this visual and need to be related with the dimension.

 

Any help is much appreciated.

 

For reference, here is a screenshot of the model.

eloomis_0-1707434829671.png

 

 

 

1 ACCEPTED SOLUTION
eloomis
Advocate II
Advocate II

I was able to fix the problem without modifying the measures - I made a mistake in merging the dimension keys with the fact tables. Thank you for the reponses!

View solution in original post

3 REPLIES 3
eloomis
Advocate II
Advocate II

I was able to fix the problem without modifying the measures - I made a mistake in merging the dimension keys with the fact tables. Thank you for the reponses!

v-rzhou-msft
Community Support
Community Support

Hi @eloomis ,

 

I think you can try this code to create a measure.

# Portfolio % =
IF (
    ISINSCOPE ( DimSector[SubSector] ),
    DIVIDE (
        [# Total_Market_Value_Base],
        CALCULATE (
            SUMX ( FactPortfolioSectorDetails, [# Total_Market_Value_Base] ),
            FILTER (
                ALLSELECTED ( FactPortfolioSectorDetails ),
                FactPortfolioSectorDetails[Asset Type Subcategory] = MAX ( DimSector[Sector] )
            )
        )
    ),
    DIVIDE (
        [# Total_Market_Value_Base],
        CALCULATE (
            SUMX ( FactPortfolioSectorDetails, [# Total_Market_Value_Base] ),
            ALLSELECTED ( FactPortfolioSectorDetails )
        )
    )
)

vrzhoumsft_0-1707459345677.png

 

Best Regards,
Rico Zhou

 

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

 

amitchandak
Super User
Super User

@eloomis , Switch measure based on level

 

# Portfolio % =
var _level1 = DIVIDE(
[# Total_Market_Value_Base],
CALCULATE(
SUMX(FactPortfolioSectorDetails,[# Total_Market_Value_Base]),
removefilters(FactPortfolioSectorDetails[Subsecor])
)
)

var _level2 = DIVIDE(
[# Total_Market_Value_Base],
CALCULATE(
SUMX(FactPortfolioSectorDetails,[# Total_Market_Value_Base]),
ALLSELECTED(FactPortfolioSectorDetails)
)
)

return
if(isinscope(FactPortfolioSectorDetails[Subsecor]), _level1, _level2)

 

 

How to Switch Subtotal and Grand Total in Power BI | Power BI Tutorials| isinscope: https://youtu.be/smhIPw3OkKA

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.