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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
pobasu
Employee
Employee

Data Modeling with 2 Fact Tables

I have the following 2 Tables :- 

Account Details

pobasu_0-1602021821439.png

Person Details

pobasu_1-1602021932237.png

 

Now each account can have multiple persons associated with it and one person can manage multiple accounts

Let's take the below example :-

pobasu_2-1602022131832.png

 

I also have a Top N filter table where I have values for each Top N%

pobasu_3-1602022256883.png

The above table means that when I select Top 50%, I need to select the top 50% accounts by revenue , within the context of other filters like Area 

I am trying to do the following :-

1. When user selects a Top N% Value (Let's say Top 50%) , a visual should return the top N% accounts by revenue 

2. Upon the same action, another visual should return the list of persons who are associated with the account and their Target and Actual (Ideally 1 row per person) 

I am wondering what would be a good way to model the data to achieve this , since it looks like I am filtering dimension tables(AccountId) based on filtering on Fact Tables.

 

Appreciate any help and guidance

 

 

 

 

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

Hi @pobasu ,

 

1.Create a calculated column to rank.

Rank =
RANKX (
    'Account Details',
    CALCULATE (
        SUM ( 'Account Details'[Revenue] ),
        ALLEXCEPT ( 'Account Details', 'Account Details'[AccountID] )
    ),
    ,
    ASC,
    DENSE
)

5.png

 

2.Create a measure and put it into Filters. Set show items when the value is 1.

Measure =
VAR maxrank =
    CALCULATE (
        MAX ( 'Account Details'[Rank] ),
        ALL ( 'Account Details' ),
        ALL ( 'Person Details' )
    )
RETURN
    SWITCH (
        SELECTEDVALUE ( 'Top N filter'[TOp N%] ),
        "ALL", 1,
        "Top1%",
            IF ( MIN ( 'Account Details'[Rank] ) < maxrank * 0.01, 1 ),
        "Top5%",
            IF ( MIN ( 'Account Details'[Rank] ) < maxrank * 0.05, 1 ),
        "Top50%",
            IF ( MIN ( 'Account Details'[Rank] ) < maxrank * 0.5, 1 )
    )

 6.png7.png

 

 

3.When Top50% is selected, the result is this.

8.png

You can check more details from here.

 

 

Best Regards,

Stephen Tao

 

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

3 REPLIES 3
v-stephen-msft
Community Support
Community Support

Hi @pobasu ,

 

1.Create a calculated column to rank.

Rank =
RANKX (
    'Account Details',
    CALCULATE (
        SUM ( 'Account Details'[Revenue] ),
        ALLEXCEPT ( 'Account Details', 'Account Details'[AccountID] )
    ),
    ,
    ASC,
    DENSE
)

5.png

 

2.Create a measure and put it into Filters. Set show items when the value is 1.

Measure =
VAR maxrank =
    CALCULATE (
        MAX ( 'Account Details'[Rank] ),
        ALL ( 'Account Details' ),
        ALL ( 'Person Details' )
    )
RETURN
    SWITCH (
        SELECTEDVALUE ( 'Top N filter'[TOp N%] ),
        "ALL", 1,
        "Top1%",
            IF ( MIN ( 'Account Details'[Rank] ) < maxrank * 0.01, 1 ),
        "Top5%",
            IF ( MIN ( 'Account Details'[Rank] ) < maxrank * 0.05, 1 ),
        "Top50%",
            IF ( MIN ( 'Account Details'[Rank] ) < maxrank * 0.5, 1 )
    )

 6.png7.png

 

 

3.When Top50% is selected, the result is this.

8.png

You can check more details from here.

 

 

Best Regards,

Stephen Tao

 

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

CNENFRNL
Community Champion
Community Champion

Hi, @pobasu , what you mention is a typical many-to-many relationship. You may want to refer to such guidances on this topic in detail.

https://docs.microsoft.com/en-us/power-bi/guidance/relationships-many-to-many

https://www.burningsuit.co.uk/blog/2019/07/dealing-with-many-to-many-relationships/

https://www.seerinteractive.com/blog/join-many-many-power-bi/


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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