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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
SrMatto
Frequent Visitor

Calculation involving 3 fact tables, conditions and visualization

Hi!

I am trying to achieve the following calculation:

 

Count all the programs that have been completed, considering the following conditions:

1. It should consider all the persons enrolled on that specific IdDate (defined in the slicers). i.e VALUES(DimDate[IdDate]) 

2. The completion should be on or after that IdDate. i.e FactCompletion: IdDate>=Min(FactEnrollment[IdDate]). FactEnrollment[Degree of Completion]="Complete"

3. The result should be presented in a table that has the Group and Category in which the Person was first considered, NOT when it was Completed. Also, a person can be in more than one Group during a IdDate. The info is in FactGroup

 

The data model is:   

SrMatto_0-1734392457098.png

As an example, with these slicers:

SrMatto_1-1734392560750.png

These are the Persons enrolled in 20181 and 20231 with their corresponding Groups:

SrMatto_2-1734392645665.png

From this list, the ones that have Completed a Program are:

SrMatto_3-1734392718953.png

 

Thus, it should lead to this excpected result:

SrMatto_4-1734392780997.png

Note that a person might be counted more than once depending on the Rollup.

 

I have added a table in the PIBX, the fields are what I wish to have but the values are wrong

 

link to pbix 

 

Thank you very much!

1 ACCEPTED SOLUTION

Hi @SrMatto ,

I updated your sample pbix file(see the attachment), please check if that is what you want.

1. Delete the relationship between the table 'Bridge' and 'FactCompletion'

vyiruanmsft_0-1735116067068.png

2. Create two measures as below to get the count of person ids which fulfill the conditions

Measure =
VAR _selyear =
    ALLSELECTED ( 'DimDate'[year] )
VAR _semester =
    ALLSELECTED ( 'DimDate'[semester] )
VAR _category =
    ALLSELECTED ( 'DimGroup'[Category] )
VAR _program =
    SELECTEDVALUE ( 'Table'[Program] )
VAR _personids =
    CALCULATETABLE (
        VALUES ( 'Bridge'[Person ID] ),
        FILTER (
            ALLSELECTED ( 'Bridge' ),
            'Bridge'[IdDate] IN ALLSELECTED ( 'DimDate'[IdDate] )
        )
    )
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( 'FactCompletion'[Person ID] ),
        FILTER (
            'FactCompletion',
            'FactCompletion'[Person ID]
                IN _personids
                    && 'FactCompletion'[Degree of Completion] = "Complete"
                    && 'FactCompletion'[IdDate] > MIN ( 'DimDate'[IdDate] )
                    && 'FactCompletion'[IdDate] > MIN ( 'DimDate'[IdDate] )
        )
    )
RETURN
    _count
Corrected Count =
SUMX (
    VALUES ( 'DimGroup'[Category] ),
    SUMX ( VALUES ( 'Table'[Program] ), [Measure] )
)

vyiruanmsft_2-1735116327591.png

Best Regards

Community Support Team _ Rena
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

5 REPLIES 5
SrMatto
Frequent Visitor

anyone have an idea on how to get the numbers?

Hi @SrMatto ,

I updated your sample pbix file(see the attachment), please check if that is what you want.

1. Delete the relationship between the table 'Bridge' and 'FactCompletion'

vyiruanmsft_0-1735116067068.png

2. Create two measures as below to get the count of person ids which fulfill the conditions

Measure =
VAR _selyear =
    ALLSELECTED ( 'DimDate'[year] )
VAR _semester =
    ALLSELECTED ( 'DimDate'[semester] )
VAR _category =
    ALLSELECTED ( 'DimGroup'[Category] )
VAR _program =
    SELECTEDVALUE ( 'Table'[Program] )
VAR _personids =
    CALCULATETABLE (
        VALUES ( 'Bridge'[Person ID] ),
        FILTER (
            ALLSELECTED ( 'Bridge' ),
            'Bridge'[IdDate] IN ALLSELECTED ( 'DimDate'[IdDate] )
        )
    )
VAR _count =
    CALCULATE (
        DISTINCTCOUNT ( 'FactCompletion'[Person ID] ),
        FILTER (
            'FactCompletion',
            'FactCompletion'[Person ID]
                IN _personids
                    && 'FactCompletion'[Degree of Completion] = "Complete"
                    && 'FactCompletion'[IdDate] > MIN ( 'DimDate'[IdDate] )
                    && 'FactCompletion'[IdDate] > MIN ( 'DimDate'[IdDate] )
        )
    )
RETURN
    _count
Corrected Count =
SUMX (
    VALUES ( 'DimGroup'[Category] ),
    SUMX ( VALUES ( 'Table'[Program] ), [Measure] )
)

vyiruanmsft_2-1735116327591.png

Best Regards

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

Amazing.
Perfect timing for a christams gift!
Thank you so very much @v-yiruan-msft 

SrMatto
Frequent Visitor

thank you for your reply, but it's nowhere near the expected result. 
also, it doesn't solve the requirement of cross filtering 3 fact tables. (Or maybe i misunderstood your reply?)

lbendlin
Super User
Super User

Here is how I would refactor the data model. Avoid bridge tables, avoid joining fact tables, avoid bidirectionals.

 

lbendlin_0-1734400424413.png

 

lbendlin_1-1734400806740.png

 

 

Helpful resources

Announcements
ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.