Scripts icon indicating copy to clipboard operation
Scripts copied to clipboard

Added new community scripts

Open MattAlington opened this issue 5 years ago • 2 comments

MattAlington avatar Oct 17 '20 00:10 MattAlington

Thanks for your contribution Matt.

Unfortunately, I can't approve the "Replace text strings that occur in many measures" script, since it is too specific. What if my model doesn't have a [Total Sales] measure? What if the original measure was formatted so there would be spaces or line breaks between CALCULATE and SUM? What about the many other possible table/column names that could also occur?

I recommend changing this to some kind of pattern matching. Preferably, use the Measure.Tokenize() function which would return a list of tokens for the DAX expression, making it easier to find a pattern containing the following tokens (in order), ignoring any whitespace, line breaks or comments:

  1. DaxToken.CALCULATE
  2. DaxToken.OPEN_PARENS
  3. DaxToken.SUM
  4. DaxToken.OPEN_PARENS
  5. DaxToken.COLUMN_OR_MEASURE
  6. DaxToken.CLOSE_PARENS

You can use the same pattern matching technique to build an index of all existing measures, to check whether a suitable measure could be replaced, or if a new measure has to be created.

otykier avatar Oct 21 '20 09:10 otykier

I copied this repo and added your file to the following Repo: https://github.com/PowerBI-tips/TabularEditor-Scripts/blob/main/Basic/Create%20Build%20direct%20or%20indirect%20dependency%20tree%20of%20selected%20or%20all%20measures.csx

You are welcome to continue to contribute to this repo as I am actively maintaining the Tabular Editor scripts there: https://github.com/PowerBI-tips/TabularEditor-Scripts

MikeCarlo avatar Sep 22 '21 17:09 MikeCarlo