Forum Discussion
Divinal_ThiagoP
2 years agoRegular Visitor
Filtering data from PostgreSQL with no date field in Power BI
Hi everyone,
I'm new to Power BI and I'm having some trouble connecting to a PostgreSQL database and importing the data.
Background:
- My company uses a PostgreSQL database.
- I'm using ODBC to connect to the database.
- I need to filter the data to only include the last 2 years.
- Example: If you are in 2024, I need the data from 2023 and 2022. But next year (2025), the data selection should automatically update to only include data from 2023 onwards.
- Some tables don't have a date field.
My question is: which is the most eficient way to filter this data?
Thanks in advance for your help!
Hello Divinal_ThiagoP,
You could write a query that joins your target table with the date-containing table and filters based on the date:
SELECT t.*, d.date_field FROM target_table t JOIN date_table d ON t.date_id = d.id WHERE d.date_field >= CURRENT_DATE - INTERVAL '2 years'Hope this helps!
1 Reply
- Sahir_MaharajSuper User
Hello Divinal_ThiagoP,
You could write a query that joins your target table with the date-containing table and filters based on the date:
SELECT t.*, d.date_field FROM target_table t JOIN date_table d ON t.date_id = d.id WHERE d.date_field >= CURRENT_DATE - INTERVAL '2 years'Hope this helps!