Forum Discussion

ChristophEmrich's avatar
ChristophEmrich
Frequent Visitor
7 years ago
Solved

Divide values from different tables

Hi all,

 

I am trying to calculate the market share of certain products in a specfic country, in a specific year based on filtered values. For that I have two tables: Table_Sales and Table_Market and two slicers: Year and Country.

 

In the Table_Sales I have the list of products and their sales volumes in each country and each year:

YearCountryProductSales
2018FranceChocolate240
2018FranceStrawberry60
2018FranceVanilla168
2018GermanyChocolate100
2018GermanyStrawberry20
2018GermanyVanilla170
2018ItalyChocolate48
2018ItalyStrawberry32
2018ItalyVanilla56
2019FranceChocolate60
2019FranceStrawberry108
2019FranceVanilla168
2019GermanyChocolate12
2019GermanyStrawberry180
2019GermanyVanilla48
2019ItalyChocolate120
2019ItalyStrawberry60
2019ItalyVanilla160
2020FranceChocolate320
2020FranceStrawberry144
2020FranceVanilla48
2020GermanyChocolate150
2020GermanyStrawberry135
2020GermanyVanilla300
2020ItalyChocolate32
2020ItalyStrawberry56
2020ItalyVanilla152

 

In the Table_Market, I have the total market volume each year in each country:

YearCountryMarket Volume
2018Germany1,000
2018Italy800
2018France1,200
2019Germany1,200
2019Italy1,000
2019France1,200
2020Germany1,500
2020Italy800
2020France1,600

 

 

Now I somehow need to connect the tables and create a measure. I have a relationship on the key YEAR_COUNTRY but other than that, I don't know how to do it.

 

What I'd like to see is if in the slicers the selected values are "Select all", of course I'd like to see the market share of all products comined in all years and in all markets. If a year is selected, it should only be that year's market share.

 

I've tried a lot of stuff already, with SUMX, CALCULATE and others but nothing seems to work.

 

Hope I could make myself clear. Would appreciate any help! Thank you.

Christoph

  • Anonymous's avatar
    Anonymous
    7 years ago

    Hi,

    I think you need two calculated tables and three measures.

     

    Table 1: Calendar

     

    Calendar =
    DISTINCT ( UNION ( ALL ( Table_Market[Year] ), ALL ( Table_Sales[Year] ) ) )

    Table 2: Countries

    Countries =
    DISTINCT (
        UNION ( ALL ( Table_Market[Country] ), ALL ( Table_Sales[Country] ) )
    )

    Relationships:

    Countries[Country] -> Table_Market[Country]
    
    Countries[Country] -> Table_Sales[Country]
    
    Calendar[Year] -> Table_Market[Year]
    
    Calendar[Year] -> Table_Sales[Year]

    All relationships are one to many with cross-filtering as single.

     

    Measure 1: MarketSize

    MarketSize = SUMX(Table_Market,Table_Market[Market Volume])

    Measure 2: SalesVolume

    SalesVolume = SUMX(Table_Sales,Table_Sales[Sales])

    Measure 3: MarketShare %

    Market Share = DIVIDE(Table_Sales[SalesVolume],Table_Market[MarketSize],0)

    For the slicers, use the Calendar[Year] and Countries[Country] fields.

     

    MarketSize, SalesVolume, and MarketShare% will be correctly displayed.

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi,

    I think you need two calculated tables and three measures.

     

    Table 1: Calendar

     

    Calendar =
    DISTINCT ( UNION ( ALL ( Table_Market[Year] ), ALL ( Table_Sales[Year] ) ) )

    Table 2: Countries

    Countries =
    DISTINCT (
        UNION ( ALL ( Table_Market[Country] ), ALL ( Table_Sales[Country] ) )
    )

    Relationships:

    Countries[Country] -> Table_Market[Country]
    
    Countries[Country] -> Table_Sales[Country]
    
    Calendar[Year] -> Table_Market[Year]
    
    Calendar[Year] -> Table_Sales[Year]

    All relationships are one to many with cross-filtering as single.

     

    Measure 1: MarketSize

    MarketSize = SUMX(Table_Market,Table_Market[Market Volume])

    Measure 2: SalesVolume

    SalesVolume = SUMX(Table_Sales,Table_Sales[Sales])

    Measure 3: MarketShare %

    Market Share = DIVIDE(Table_Sales[SalesVolume],Table_Market[MarketSize],0)

    For the slicers, use the Calendar[Year] and Countries[Country] fields.

     

    MarketSize, SalesVolume, and MarketShare% will be correctly displayed.