Forum Discussion

RedOcean's avatar
RedOcean
Frequent Visitor
9 years ago
Solved

Creating matrix from two tables and a calculation

Hello,   I have two tables with these fields;   Community (of agents) Agent ID Country Rank (1 to 10) Referal Channel Joining Date Referal Spend Referal Channel  Total Spend   I w...
  • RedOcean's avatar
    RedOcean
    9 years ago

    I am really grateful for your help.

     

    Below is a link.

     

    there are 3 tables, linked.

     

    I have shown a single with 2 table visualisations on sheet "Recruit$ L2+" 

     

    They show 1) the total number of new agents, by month/country/recruitment-channel that have an RPLevel>1

    2) The total $ spend on each recruitment-channel by month/country

     

    What I require is a new table that shows me average cost recruitment cost of agents each month that have RPLevel>1.

     

    For example, in Hong Kong in 2017-7 we spent $137.34 and have 36 agents recruited in that month that are RPLevel>1. So the average should be $3.82

     

    Many thanks for your help!

     

    https://www.dropbox.com/sh/kloegc6bsenuxd3/AADaBUOrZ90b63guu7WA73BEa?dl=0

     

  • v-ljerr-msft's avatar
    v-ljerr-msft
    9 years ago

    Hi RedOcean,

     

    Based on my test, the formula below should work in your scenario. :smileyhappy:

    Measure =
    VAR currentCountry =
        FIRSTNONBLANK ( 'Community Recruitment Spend'[Country], 1 )
    VAR currentReferalSourceID =
        MAX ( 'Community Recruitment Spend'[Referal Source ID] )
    VAR currentMonth =
        MONTH ( MAX ( 'Community Recruitment Spend'[Month] ) )
    VAR currentYear =
        YEAR ( MAX ( 'Community Recruitment Spend'[Month] ) )
    RETURN
        DIVIDE (
            (
                DIVIDE (
                    SUM ( 'Community Recruitment Spend'[Spend (USD)] ),
                    CALCULATE (
                        COUNTA ( CommunityView[AgentID] ),
                        FILTER (
                            ALL ( CommunityView ),
                            CommunityView[CountryName] = currentCountry
                                && CommunityView[ReferralSourcesId] = currentReferalSourceID
                                && MONTH ( CommunityView[RegistrationDate] ) = currentMonth
                                && YEAR ( CommunityView[RegistrationDate] ) = currentYear
                                && CommunityView[RPLevel] > 1
                        )
                    )
                )
            ),
            DISTINCTCOUNT ( 'Community Recruitment Spend'[SpendYearMonth] )
        )
    

     

    Regards