cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Zepox
Frequent Visitor

Define relationship between tables

Hello,

 

On SQLBI, there is the following code in an article: 

 

 

Test :=
SUMX (
    FILTER (
        Customer,
        Customer[Country] = "United States"
    ),
    SUMX (
        FILTER (
            Sales,
            Sales[CustomerKey] = Customer[CustomerKey] &&
            Customer[Age] >= 20
        ),
        IF (
            Customer[Age] <= 45,
            Sales[Quantity] * Sales[Net Price],
            Sales[Quantity] * Sales[Unit Price]
        )
    )
)

 

 

 

Now I don't need the first FILTER part. But if I remove that  Sales[CustomerKey] = Customer[CustomerKey] won't work anymore. The question is how do I define this relationship without the first FILTER. I could just set a filter that is always true but I'd like to learn how to properly do it.

 

Kind regards,

2 REPLIES 2
amitchandak
Super User
Super User

@Zepox , if sales and customers already have a join in the model then you do not need that join here.

For example here is my situation:

VAR hours =
    SUMX (
        FILTER ( 'order_completion', 'order_completion'[Date] > DATE ( 1900, 1, 1 ) ),
        SUMX (
            FILTER ( 'work_log', 'work_log'[ID] = 'order_completion'[ID] ),
            'work_log'[working_duration] / 'order_completion'[amount_completed]
        )
    )

 

There are 2 tables (order_completion and work_log), both have ID but there is a table between them which connects them. If I remove the top part with the uselss filter I get the following error: a single value column cannot be determined.

 

I need to find the total worked time per item by dividing the total amount of worktime logged in 1 table by the amount of items completed logged in another table. The above code works but obviously is not the cleanest.

Helpful resources

Announcements
PBI Sept Update Carousel

Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

Learn Live

Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

MPPC 2023 PBI Carousel

Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors