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
thod
Helper I
Helper I

Count number of Power Query applied steps in Power BI

Hi,

I have gathered metadata from our Power BI tenant through the scanner API.

In this I have "let" expressions (power query advanced editor) from all semantic models and I want to count the number of applied steps in used for each table in these semantic models. Some examples of "let" expressions are:

No. 1 - One applied step:
 let
Source = Sql.Database(#"Server Prod - Dataplatform", #"Database Prod - SharedDimensions", [Query="SELECT [DW_SK_Brand]#(lf) ,[BrandId]#(lf) ,[Brand]#(lf) ,[BrandBeskrivelse]#(lf) FROM [DSO_SharedDimensions].[all].[DimBrand]"])
in
Source

 

No 2. - Two applied steps:
let
Source = Sql.Database(#"Server Prod - Dataplatform", #"Database Prod - SharedDimensions"),
dpa_FctBeregninger = Source{[Schema="all",Item="FctBeregninger"]}[Data]
in
dpa_FctBeregninger

No 3 - Three applied steps:
let
Source = Sql.Database(#"Server Prod - Dataplatform", #"Database Prod - SharedDimensions", [Query="SELECT [DW_SK_Produkt]#(lf) ,[ProduktID]#(lf) ,Produkt#(lf) ,Produktgruppe#(lf) ,[ProduktBeskrivelse]#(lf) ,[ProduktBeskrivelseENG]#(lf) FROM [DSO_SharedDimensions].[all].[DimProdukt]"]),
#"Filtered Rows" = Table.SelectRows(Source, each ([ProduktID] = 1000000 or [ProduktID] = 1000001)),
#"Changed Type" = Table.TransformColumnTypes(#"Filtered Rows",{{"DW_SK_Produkt", Int64.Type}})
in
#"Changed Type"

So two sum up, I want a measure that calculates how many applied steps there is for each "let" expression in the dataset.

Br.,
Thomas

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@thod Simple enough. PBIX below sig.

 

Measure = 
    VAR __Text = MAX('Table'[Column1])
    VAR __Length = LEN(__Text)
    VAR __Replace = SUBSTITUTE( __Text, "," & UNICHAR(10), "" )
    VAR __NewLength = LEN(__Replace)
    VAR __Diff = __Length - __NewLength
    VAR __Result = DIVIDE( __Diff, 2 ) + 1
RETURN
    __Result

 


@ 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...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@thod Simple enough. PBIX below sig.

 

Measure = 
    VAR __Text = MAX('Table'[Column1])
    VAR __Length = LEN(__Text)
    VAR __Replace = SUBSTITUTE( __Text, "," & UNICHAR(10), "" )
    VAR __NewLength = LEN(__Replace)
    VAR __Diff = __Length - __NewLength
    VAR __Result = DIVIDE( __Diff, 2 ) + 1
RETURN
    __Result

 


@ 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...

Hi @Greg_Deckler ,
Thank you very much. I had to modify your measure a tiny bit, as it for some reason included a lot of tables that is not a part of the data set with the result of one.
So the modified measure that works is:

measure =
VAR __Text =
    MAX ( 'Table'[Column1] )
VAR __Length =
    LEN ( __Text )
VAR __Replace =
    SUBSTITUTE ( __Text, "," & UNICHAR ( 10 ), "" )
VAR __NewLength =
    LEN ( __Replace )
VAR __Diff = __Length - __NewLength
VAR __Result =
    IF ( ISBLANK ( __Length ), BLANK (), DIVIDE ( __Diff, 2 ) + 1 )
RETURN
    __Result


Br,
thod

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.