Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Max
Frequent Visitor

SQL to DAX help request - Project Online data

I need help with querying data and I must confess being humbled by my DAX (or it is M?) current ignorance.

 

I have Projects in Project Online. I want to track some of them in a dashboard in Power BI.
A Custom Enterprise field called "TrackInPowerBI" was created, and it was set to "true" for the projects to be tracked to.

 

Connecting with oData was easy.

 

Selecting just those projects was easy:

 

let
Source = OData.Feed("https://mycustomer.sharepoint.com/sites/pwa/_api/ProjectData"),
Projects_table = Source{[Name="Projects",Signature="table"]}[Data],
#"Select Columns" = Table.SelectColumns(Projects_table,{"ProjectId", "ProjectActualCost", "ProjectActualDuration"...
... "TotalBenefits", "TotalCost", "TrackInPowerBI","Country", "State"}),
.... more applied steps here...
#"Just Projects Tracked" = Table.SelectRows(#"Renamed Columns2", each ([TrackInPowerBI] = true))
in
#"Just Projects Tracked"

 

Works as a charm.

 

But doing this for a related table is not being easy for me.
Basically, what I need is the translation of

 

Select Tasks.*
from Tasks
where Tasks.ProjectId in (select ProjectId from Projects where Projects.TrackInPowerBI = 1)

 

or similar

 

Select Tasks.*
from Tasks join Projects
on Tasks.ProjectId = Projects.ProjectId
where Projects.TrackInPowerBI = 1

 

May somebody help me with this, pretty please?

The main issue here is that there are big tables like the TaskTimePhasedDataset that time-out when querying from PowerBI Desktop and I need to cut out all of those rows not belonging to the tracked projects.

 

Max

 

1 REPLY 1
Greg_Deckler
Super User
Super User

Here is a walk-through of creating a single Join query in M:

 

What I did was start out with two CSV files:

 

one.csv

Column1,Column2
one,10
two,20
three,30
four,40
five,50
six,60
seven,70
eight,80
nine,90

 

two.csv

Column1,Column2
one,100
two,200
three,300
four,400
five,500
six,600
seven,700
eight,800
nine,900

 

The "normal" process is to create a query for both one.csv and two.csv, then go and edit one.csv query and add a Merge step to merge two.csv query. With this method, you wind up with 2 queries, the two.csv query is in effect an intermediate query. In the Advanced editor, the code looks like:

 

two.csv

let
    Source1 = Csv.Document(File.Contents("C:\Temp\two.csv"),[Delimiter=",",Encoding=1252]),
    #"Promoted Headers1" = Table.PromoteHeaders(Source1),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers1",{{"Column1", type text}, {"Column2", Int64.Type}})
in
    #"Changed Type1"

 

one.csv

let
    Source = Csv.Document(File.Contents("C:\Temp\one.csv"),[Delimiter=",",Encoding=1252]),
    #"Promoted Headers" = Table.PromoteHeaders(Source),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Column1", type text}, {"Column2", Int64.Type}}),
    #"Merged Queries" = Table.NestedJoin(#"Changed Type",{"Column1"},two,{"Column1"},"NewColumn",JoinKind.LeftOuter),
    #"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Column2"}, {"NewColumn.Column2"})
in
    #"Expanded NewColumn"

 

However, you can use the code from these queries to create a blank query that looks like this:

 

merge query

 

let
    Source = Csv.Document(File.Contents("C:\Temp\one.csv"),[Delimiter=",",Encoding=1252]),
    Source1 = Csv.Document(File.Contents("C:\Temp\two.csv"),[Delimiter=",",Encoding=1252]),
    #"Promoted Headers" = Table.PromoteHeaders(Source),
    #"Promoted Headers1" = Table.PromoteHeaders(Source1),
    #"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Column1", type text}, {"Column2", Int64.Type}}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Promoted Headers1",{{"Column1", type text}, {"Column2", Int64.Type}})
    #"Merged Queries" = Table.NestedJoin(#"Changed Type",{"Column1"},#"Changed Type1",{"Column1"},"NewColumn",JoinKind.LeftOuter),
    #"Expanded NewColumn" = Table.ExpandTableColumn(#"Merged Queries", "NewColumn", {"Column2"}, {"NewColumn.Column2"})
in
    #"Expanded NewColumn"

 

Now you can get rid of one.csv and two.csv queries and have a single query that does it all in one query!
 

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.