Forum Discussion
GiuPowerBi
2 years agoRegular Visitor
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...
- Anonymous2 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.
- 2 years ago
pls try code in Power Query
PijushRoy
2 years agoCommunity Champion
Hi GiuPowerBi
What is the logic to declare the Foreigh key in your last screenshot
GiuPowerBi
2 years agoRegular Visitor
Hello,
logic is Date should be within other table LowerDate and Upper Date and Type should match.
Thank you