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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
kk_shp_user
Helper I
Helper I

Create a measure using a relationship and then refer it back using a different relationship

I have a Fact_Sales table where there are - month_ending, id, name, sales

 

Every id is recruited by someone else. There is a different table for hierarchy dim_hierarchy - id, recruiter_id, recruitment_date

 

I want to have measures for,

1. how many new recruits someone had in a particular month

2. how much sales did a particular recruiter get from all their new joiners

 

If I join Fact_sales[id] to dim_hierarchy[recruiter_id], it becomes a many-to-many relation. So I created a bridge table with distinct ids and used that to connect the two tables. 

 

I am able to get the first measure -  I can do this with or without a relationship using TREATAS. However I am stuck with creating the second measure, where I need to get the sales of all the new recruits for a Fact_sales[id]. The reason being, I need some way to calculate the sales for all the ids in dim_hierarchy which I have to pull from Fact_Sales and then refer this back in the measure I am trying to create.

 

kk_shp_user_0-1750273666815.png

 

 

1 ACCEPTED SOLUTION
Elena_Kalina
Solution Supplier
Solution Supplier

Hi @kk_shp_user 

Please, try these measures

Sales From Recruits = 
VAR CurrentRecruiterID = SELECTEDVALUE(Fact_Sales[id])
VAR RecruitsOfCurrentRecruiter = 
    CALCULATETABLE(
        VALUES(dim_hierarchy[id]),
        FILTER(
            ALL(dim_hierarchy),
            dim_hierarchy[recruiter_id] = CurrentRecruiterID
        )
    )
VAR SalesFromRecruits =
    CALCULATE(
        SUM(Fact_Sales[sales]),
        Fact_Sales[id] IN RecruitsOfCurrentRecruiter
    )
RETURN
    SalesFromRecruitsFor Measure #1 (Count of New Recruits)
New Recruits Count = 
VAR CurrentMonth = SELECTEDVALUE(Fact_Sales[month_ending])
VAR CurrentRecruiterID = SELECTEDVALUE(Fact_Sales[id])
RETURN
    CALCULATE(
        COUNTROWS(dim_hierarchy),
        FILTER(
            ALL(dim_hierarchy),
            dim_hierarchy[recruiter_id] = CurrentRecruiterID &&
            EOMONTH(dim_hierarchy[recruitment_date], 0) = CurrentMonth
        )
    )

View solution in original post

3 REPLIES 3
v-sgandrathi
Community Support
Community Support

HI @kk_shp_user,

 

Thankyou  @Elena_Kalina and @danextian for your reply on the issue.

Has your issue been resolved? If the community member's response answered your query, please confirm it! Marking a reply as a solution helps others with similar questions and keeps the community helpful and organized. If the response was helpful, giving Kudos is always appreciated!

 

danextian
Super User
Super User

Hi @kk_shp_user 

 

It would be easier for us to provide a more suitable solution had you provided a workable sample (not an image ) data and your expected result from that.  You may post a link to Excel or a sanitized copy of your PBIX stored in the cloud. https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447... 





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Elena_Kalina
Solution Supplier
Solution Supplier

Hi @kk_shp_user 

Please, try these measures

Sales From Recruits = 
VAR CurrentRecruiterID = SELECTEDVALUE(Fact_Sales[id])
VAR RecruitsOfCurrentRecruiter = 
    CALCULATETABLE(
        VALUES(dim_hierarchy[id]),
        FILTER(
            ALL(dim_hierarchy),
            dim_hierarchy[recruiter_id] = CurrentRecruiterID
        )
    )
VAR SalesFromRecruits =
    CALCULATE(
        SUM(Fact_Sales[sales]),
        Fact_Sales[id] IN RecruitsOfCurrentRecruiter
    )
RETURN
    SalesFromRecruitsFor Measure #1 (Count of New Recruits)
New Recruits Count = 
VAR CurrentMonth = SELECTEDVALUE(Fact_Sales[month_ending])
VAR CurrentRecruiterID = SELECTEDVALUE(Fact_Sales[id])
RETURN
    CALCULATE(
        COUNTROWS(dim_hierarchy),
        FILTER(
            ALL(dim_hierarchy),
            dim_hierarchy[recruiter_id] = CurrentRecruiterID &&
            EOMONTH(dim_hierarchy[recruitment_date], 0) = CurrentMonth
        )
    )

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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