Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Mi código actual es así
EVALUATE
VAR base ={1}
RETURN base
¿Hay alguna herramienta disponible que mate todos los frenos de la línea de código?
EVALUATE VAR base = {1} RETURN base
Estoy escribiendo una consulta AS dinámica para la que necesito que se minimice el DAX porque es mucho más fácil inyectar el parámetro en la versión minimizada.
let x = "cat1",
y = Analysis.ServiceDataBase("serverString","db",[Query="...FILTER(tbl,tbl[Category]="&x&"..)])
in
y
Gracias de antemano
No es necesario minimizar nada, ya que puede usar variables de cadena de varias líneas en Power Query
Eg
let
SourceQuery = "
EVALUATE
'Product Category'",
result = AnalysisServices.Database("localhost\tab19", "Adventure Works", [Implementation="2.0", Query=SourceQuery])
in
result
Regex es una posible solución
const regex = /\n/gm;
const str = `-- SUBSTITUTEWITHINDEX is a tool function used mainly by
-- Power BI to map values in a query to column in a matrix
-- by substituting the index columns with a number indicating
-- the column number where to put the result.
-- The matching between the two tables is based on data lineage
-- or column names.
DEFINE
VAR R =
SUMMARIZECOLUMNS (
'Product'[Brand],
'Date'[Calendar Year],
TREATAS ( { "Contoso", "Fabrikam" }, 'Product'[Brand] ),
"Amount", [Sales Amount]
)
VAR C =
SUMMARIZE ( Sales, 'Date'[Calendar Year] )
VAR C_ColumnName =
SELECTCOLUMNS({"CY 2007", "CY 2008", "CY 2009"}, "Calendar Year", [Value])
VAR Result =
SUBSTITUTEWITHINDEX ( R, "Column #", C, [Calendar Year], ASC )
EVALUATE R
EVALUATE C
EVALUATE C_ColumnName
EVALUATE Result
-- The following code would generate an error
-- because C_ColumnName has the same name
-- of a column with a data lineage
-- EVALUATE
-- SUBSTITUTEWITHINDEX ( R, "Column #", C_ColumnName, [Calendar Year], ASC )
-- The following code works because the
-- Date[Calendar Year] column loses the data lineage
-- in SELECTCOLUMNS by using an expression
EVALUATE
SUBSTITUTEWITHINDEX (
SELECTCOLUMNS (
R,
'Product'[Brand],
-- the expression remove the data lineage
"Calendar Year", 'Date'[Calendar Year] & "",
[Amount]
),
"Column #", C_ColumnName, [Calendar Year], ASC
)`;
const subst = ` `;
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.