Forum Discussion

PranjaliB's avatar
PranjaliB
Frequent Visitor
7 years ago

How to create Select query with where clause with AND condition in Power BI

Hi ,

I am creating Power BI reports  and Some SQL queries are like this in which @StartDate,@FinishDate,@DepSelection are query parameter

 

SELECT DISTINCT
p.[ProjectUID], p.[Project code]
FROM Project p
JOIN Assignment abd ON abd.ProjectUID = p.ProjectUID
AND abd.AssignmentWork <> 0
AND abd.TaskIsActive = 1
AND abd.TimeByDay BETWEEN (@StartDate) and (@FinishDate)
WHERE [Project code] is not null
AND ISNULL(p.Archived, 'No') = 'No'
AND p.[Project Departments] IN (@DepSelection)
ORDER BY p.[Lawson Code]

 

How to create above query in Power BI desktop.or complex joins on tables .Urgent Help appreciated!!

6 Replies

  • AnkitBI's avatar
    AnkitBI
    Icon for Solution Sage rankSolution Sage

     

    Can achieve by using Parameters in PBI Desktop. Please check below Post or any Post on how to add Parameters in SQL Query in PBI Desktop. Parameters

     

    Regards
    AJ
    Do Like Post if response seems good and Worth liking.
    Do Mark as Solution if response resolved your Issue.

     

    • PranjaliB's avatar
      PranjaliB
      Frequent Visitor

      Hi Ankit 

      I am looking how to create select query in power bi with mutiple joins and logical conditions

      • AnkitBI's avatar
        AnkitBI
        Icon for Solution Sage rankSolution Sage

        You can directly write your queries using Advanced option in SQL source. It allows using All SQL functions.  Try following steps

        1) Write your SQL query in Advanced option. Give sample values instead of variables like FirstDate etc.

        2) Once data is imported, create Power BI parameters for your SQL Query.

        3) Go to Advanced Editor and Replace sample values with your newly created Parameters. Check the link I shared or any other link online.

        4) Click on Refresh, your data will now be imported based on values provided in Parameters.

         

        Unfortuately, don't have time to create Source and then End to End PBIX file.