Forum Discussion

GiuPowerBi's avatar
GiuPowerBi
Regular Visitor
2 years ago
Solved

PowerQuery. Building a FK based on condition in Foreign Table

Hello, I would like to create a foreign key on my fact table based on conditions on another table. In particulare need to retrive the key base on a range of date and on another column.   Followin...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi GiuPowerBi ,

    Based on the information you have provided, you can follow the steps below:

    1.Add new column.

    Key =
    IF (
        'Table'[Type] = "Employee"
            && 'Table'[Date] >= MAX ( 'Table2'[Lower Date] )
            && 'Table'[Date] <= MAX ( 'Table2'[Upper Date] ),
        1,
        IF (
            'Table'[Type] = "Freelance"
                && 'Table'[Date] >= MAX ( 'Table2'[Lower Date] )
                && 'Table'[Date] <= MAX ( 'Table2'[Upper Date] ),
            2,
            IF (
                'Table'[Type] = "Employee"
                    && 'Table'[Date] >= MIN ( 'Table2'[Lower Date] )
                    && 'Table'[Date] <= MIN ( 'Table2'[Upper Date] ),
                3,
                4
            )
        )
    )
    

     Final output:

     

    How to Get Your Question Answered Quickly - Microsoft Fabric Community

    If it does not help, please provide more details with your desired out put and pbix file without privacy information.

     

    Best Regards,

    Ada Wang

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