Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
5 years ago

Help adding columns from another table to an existing query

Greetings,

I am running the following query in PowerBi. It works well, but I need to pull data from another table, and add it to the output. highlighted below is the table & columns I want to extract data from.

let
Source = Sql.Database("DCSQLPA01", "Operations", [Query="SELECT TOP (100) PERCENT RTRIM(r.Name) AS rName, pr.Type, pr.Sequence, d.ParkRideID, pr.RideName, DATEDIFF(minute, d.TimeDown, d.TimeUp) AS DownTimeMins, d.TimeDown, d.TimeUp, s.Name, RTRIM(d.Reason) AS Reason, #(lf) RTRIM(d.Resolution) AS Resolution, RTRIM(d.Comments) AS Comments, pr.ParkID, p.Name AS Expr1#(lf)FROM dbo.ParkRideDowntimes AS d INNER JOIN#(lf) dbo.ParkRides AS pr ON pr.ID = d.ParkRideID INNER JOIN#(lf) dbo.Parks AS p ON pr.ParkID = p.ID INNER JOIN#(lf) dbo.DowntimeSubtypes AS s ON d.DowntimeSubtypeID = s.ID INNER JOIN#(lf) dbo.Rides AS r ON pr.RideID = r.ID#(lf)WHERE (d.timedown between '2019-05-03' and '2019-05-11') or (d.timedown between '2020-05-03' and '2020-05-11') or (d.timedown between '2021-05-03' and '2021-05-11')"]),
#"Sorted Rows" = Table.Sort(Source,{{"TimeDown", Order.Descending}})
in
#"Sorted Rows"

 

I want to pull  three columns and have them be in the report.

Date

TimeOpen

TimeClose

From: 

DCSQLPA01.Operations.dbo.ParkDailySchedules

I tried just adding it to the query, then tried a join. Neither worked. Hoping one of you folks knows how to write the statement I can add to my query.

 

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    I see you already have multiple joins in your query. Why can't you just join on DCSQLPA01.Operations.dbo.ParkDailySchedules and select the 3 columns you need? Try the query with this new join directly on the SQL server for testing purposes. If it works, then you shouldn't face any issue importing it to Power BI

    • Anonymous's avatar
      Anonymous
      Not applicable

      I tried that, maybe I am writing the the statement incorrectly?

  • v-jingzhang's avatar
    v-jingzhang
    Community Support

    Hi Anonymous 

     

    What is the relationship between ParkDailySchedules table and other tables already in your query? Is there any field we can use to join the query?

     

    Regards,
    Community Support Team _ Jing

    • Anonymous's avatar
      Anonymous
      Not applicable

      I know there is a field  called  ParkID that is used in both Tables, would that work?