Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
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.
Following example hope will clarify:
and my resulting table should be:
Any help on this?
Thank you
Solved! Go to Solution.
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.
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.
Hi @GiuPowerBi
What is the logic to declare the Foreigh key in your last screenshot
Proud to be a Super User! | |
Hello,
logic is Date should be within other table LowerDate and Upper Date and Type should match.
Thank you
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
86 | |
80 | |
53 | |
39 | |
39 |
User | Count |
---|---|
104 | |
85 | |
47 | |
44 | |
43 |