Forum Discussion
Power Bi Report Builder - DAX Query from Performance analyzer multiple parameter values issue
- 4 years ago
So the basic order of operations for building a query as an expression is as follows:
1) you create a new data set and link it to a connection.
2) then you click the fx button to open the expression editor
3) then you start the expression with an equals and an opening double quote character eg. ="
4) then I normally open a text editor paste my query in there and do a global search for any double quote characters " and replace them with 2 double quote characters ""5) then you paste in your query and at the end you add a closing double quote character "
="DEFINE VAR __DS0FilterTable = TREATAS({2021}, 'DateTable'[Received]) VAR __DS0FilterTable2 = TREATAS({""November""}, 'CCST'[MonthName]) VAR __DS0FilterTable3 = TREATAS({""LEGACY""}, 'CCST'[Model]) VAR __DS0FilterTable4 = TREATAS({""DIY""}, 'CCST'[Type]) VAR __DS0FilterTable5 = TREATAS({""Normal""}, 'CCST'[Status]) VAR __DS0FilterTable6 = TREATAS({""OTHERS""}, 'CCST'[Category]) EVALUATE TOPN( 501, SUMMARIZECOLUMNS( ROLLUPADDISSUBTOTAL( 'LocalDateTable_9a516b7e-ac4d-49d6-a22c-5318bf076cd8'[Year], ""IsGrandTotalRowTotal"", ROLLUPGROUP( 'LocalDateTable_9a516b7e-ac4d-49d6-a22c-5318bf076cd8'[Month], 'LocalDateTable_9a516b7e-ac4d-49d6-a22c-5318bf076cd8'[MonthNo] ), ""IsDM0Total"" ), __DS0FilterTable, __DS0FilterTable2, __DS0FilterTable3, __DS0FilterTable4, __DS0FilterTable5, __DS0FilterTable6, ""SumReceived"", CALCULATE(SUM('CCST'[Qty])), ""Good"", 'CCST'[Good], ""Good__"", 'CCST'[Good %] ), [IsGrandTotalRowTotal], 1, 'LocalDateTable_9a516b7e-ac4d-49d6-a22c-5318bf076cd8'[Year], 1, [IsDM0Total], 1, 'LocalDateTable_9a516b7e-ac4d-49d6-a22c-5318bf076cd8'[MonthNo], 1, 'LocalDateTable_9a516b7e-ac4d-49d6-a22c-5318bf076cd8'[Month], 1 ) ORDER BY [IsGrandTotalRowTotal], 'LocalDateTable_9a516b7e-ac4d-49d6-a22c-5318bf076cd8'[Year], [IsDM0Total], 'LocalDateTable_9a516b7e-ac4d-49d6-a22c-5318bf076cd8'[MonthNo], 'LocalDateTable_9a516b7e-ac4d-49d6-a22c-5318bf076cd8'[Month] "So the above is just a hard coded expression, to incorporate parameters in you would take the exising hard coded filters and replace them. So the following month filter
TREATAS({""November""}, 'CCST'[MonthName])would become something like the following to manually join in the value from a parameter called Month
TREATAS({""" + Parameters!Month.Value + """}, 'CCST'[MonthName]) - 4 years ago
Anonymous wrote:
I'm not experiencing an error. so far i encountered no data displayed on my report. Imap the query field to field by copying the one from the query code.
This will be the cause of your problem. Because of the way Report Builder executes dax queries certain characters in the fields names get replaced with underscores. So if you have not mapped using the correctly encoded names you will just get an empty string in your fields. So if you have asked for the field "[Sales Amount]" but the query engine in Report Builder returns it as "__Sales_Amount__" then your dataset will contain rows, but all the fields will be blank.
It is much easier to use the approach I suggested in my previous reply and paste in the raw query first and let Report Builder generate the field mappings before you turn your query into an expression.
I have a similiar case but instead of using parameters for the filter I want to use parameters to dynamically bring a different field. The problem with that is that summrize columns does not give aliases to the columns So I wouldn't know what to name it in the Fields section. I tried Nesting SelectedColumns on top of Summarize but then I would get empty values for "Actuals" column
="DEFINE
VAR __DS0Core =
SUMMARIZECOLUMNS(
'Dim_Acc'[GEN_MEMBER3_DESC],
'Dim_Acc'[GEN_MEMBER4_DESC],
'Dim_Acc'[GEN_MEMBER4_ID],
'Dim_Acc'[GEN_MEMBER5_DESC],
'Dim_Acc'[GEN_MEMBER5_ID],
'Dim_CostCenter'[Segment ID Desc],
(""" + Parameters!Field.Value + """),
""Actuals MTD"", 'Financial_Measures'[Actuals MTD]
)
EVALUATE
__DS0Core
"
Anonymous wrote:
I tried Nesting SelectedColumns on top of Summarize but then I would get empty values for "Actuals" column
This is the only approach I can think of for this scenario. What did your expression look like for the SELECTCOLUMNS function?
- Anonymous4 years agoNot applicable
This is what I actually ran for testing purposes
DEFINE VAR __DS0FilterTable = TREATAS({"No Calc"}, 'Analytic'[Analytic]) VAR __DS0FilterTable2 = TREATAS({"Periodic"}, 'ViewTyp'[View]) VAR __DS0FilterTable3 = TREATAS({"Dec-21"}, 'Dim_Date'[Month]) VAR __DS0FilterTable4 = TREATAS({"TSG"}, 'Dim_CostCenter'[SEGMENT_CD]) VAR __DS0FilterTable5 = TREATAS( {("TSG - Title Services Segment", "DTO - Domestic Title Operations")}, 'Dim_CostCenter'[Segment ID Desc], 'Dim_CostCenter'[Subsegment ID Desc] ) VAR __DS0Core = SELECTCOLUMNS( SUMMARIZECOLUMNS( 'Dim_Acc'[GEN_MEMBER3_DESC], 'Dim_Acc'[GEN_MEMBER4_DESC], 'Dim_Acc'[GEN_MEMBER4_ID], __DS0FilterTable, __DS0FilterTable2, __DS0FilterTable3, __DS0FilterTable4, __DS0FilterTable5, "Actuals_MTD", 'Financial_Measures'[Actuals MTD] ), "Acc 4", 'Dim_Acc'[GEN_MEMBER4_DESC], "Actuals_MTD", [Actuals MTD] ) EVALUATE __DS0Coreand this is the result
Results removing the selectColumns part:
I'm thinking that maybe using summarize instead of summarizeColumns could be an option.
- d_gosbell4 years agoSuper User
I think the issue is that inside your SUMMARIZECOLUMNS you are aliasing the column as "Actuals_MTD" then you are referencing it with a space in the SELECTCOLUMNS. The last line of your SELECTCOLUMNS should look as follows since it is operating on the output from the SUMMARIZECOLUMNS which does not have a column called [Actuals MTD]
"Actuals_MTD", [Actuals_MTD] - Anonymous4 years agoNot applicable
d_gosbell I noticed I was using the wrong name for the Actuals, I was missing the under score. Not it works!
DEFINE VAR __DS0FilterTable = TREATAS({"No Calc"}, 'Analytic'[Analytic]) VAR __DS0FilterTable2 = TREATAS({"Periodic"}, 'ViewTyp'[View]) VAR __DS0FilterTable3 = TREATAS({"Dec-21"}, 'Dim_Date'[Month]) VAR __DS0FilterTable4 = TREATAS({"TSG"}, 'Dim_CostCenter'[SEGMENT_CD]) VAR __DS0FilterTable5 = TREATAS( {("TSG - Title Services Segment", "DTO - Domestic Title Operations")}, 'Dim_CostCenter'[Segment ID Desc], 'Dim_CostCenter'[Subsegment ID Desc] ) VAR __DS0Core = SELECTCOLUMNS( SUMMARIZECOLUMNS( 'Dim_Acc'[GEN_MEMBER3_DESC], 'Dim_Acc'[GEN_MEMBER4_DESC], 'Dim_Acc'[GEN_MEMBER4_ID], __DS0FilterTable, __DS0FilterTable2, __DS0FilterTable3, __DS0FilterTable4, __DS0FilterTable5, "Actuals_MTD", 'Financial_Measures'[Actuals MTD] ), "Acc 4", 'Dim_Acc'[GEN_MEMBER4_DESC], "Actuals_MTD", [Actuals_MTD] ) EVALUATE __DS0CoreNow I'm facing anothe issue after putting in the parameter in the query
="DEFINE VAR __DS0FilterTable = TREATAS({""No Calc""}, 'Analytic'[Analytic]) VAR __DS0FilterTable2 = TREATAS({""Periodic""}, 'ViewTyp'[View]) VAR __DS0FilterTable3 = TREATAS({""Dec-21""}, 'Dim_Date'[Month]) VAR __DS0FilterTable4 = TREATAS({""TSG""}, 'Dim_CostCenter'[SEGMENT_CD]) VAR __DS0FilterTable5 = TREATAS( {(""TSG - Title Services Segment"", ""DTO - Domestic Title Operations"")}, 'Dim_CostCenter'[Segment ID Desc], 'Dim_CostCenter'[Subsegment ID Desc] ) VAR __DS0Core = SelectColumns( SUMMARIZECOLUMNS( 'Dim_Acc'[GEN_MEMBER3_DESC], 'Dim_Acc'[GEN_MEMBER4_DESC], 'Dim_Acc'[GEN_MEMBER4_ID], 'Dim_Acc'[GEN_MEMBER5_DESC], 'Dim_Acc'[GEN_MEMBER5_ID], 'Dim_Acc'[GEN_MEMBER6_DESC], 'Dim_Acc'[GEN_MEMBER6_ID], 'Dim_Acc'[GEN_MEMBER7_DESC], 'Dim_Acc'[GEN_MEMBER7_ID], 'Dim_Acc'[GEN_MEMBER8_DESC], 'Dim_Acc'[GEN_MEMBER8_ID], 'Dim_Acc'[GEN_MEMBER9_DESC], 'Dim_Acc'[GEN_MEMBER9_ID], 'Dim_Acc'[GEN_MEMBER10_DESC], 'Dim_CostCenter'[Segment ID Desc], (""" + Parameters!CC_Group.Value + """), __DS0FilterTable, __DS0FilterTable2, __DS0FilterTable3, __DS0FilterTable4, __DS0FilterTable5, ""Actuals_MTD"", 'Financial_Measures'[Actuals MTD] ), ""ACC_3"", 'Dim_Acc'[GEN_MEMBER3_DESC], ""ACC_4"", 'Dim_Acc'[GEN_MEMBER4_DESC], ""CFIELD"", (""" + Parameters!CC_Group.Value + """), ""Actuals"", [Actuals_MTD] ) EVALUATE __DS0Core "But when I run the querry using 'Dim_CostCenter'[Subsegment ID Desc] as the paremeter value I get the following:
I tried running it without parenthesis around the parameter but still the same.
- d_gosbell4 years agoSuper User
The way you are doing it at the moment will insert the column reference as a string in paranthesis so the value would come out as ("'Dim_CostCenter'[Subsegment ID Desc]") which is not valid. You probably just need to remove the paranthesis and 2 of the double quotes so that you just inject the column reference.
eg.
="DEFINE VAR __DS0FilterTable = TREATAS({""No Calc""}, 'Analytic'[Analytic]) VAR __DS0FilterTable2 = TREATAS({""Periodic""}, 'ViewTyp'[View]) VAR __DS0FilterTable3 = TREATAS({""Dec-21""}, 'Dim_Date'[Month]) VAR __DS0FilterTable4 = TREATAS({""TSG""}, 'Dim_CostCenter'[SEGMENT_CD]) VAR __DS0FilterTable5 = TREATAS( {(""TSG - Title Services Segment"", ""DTO - Domestic Title Operations"")}, 'Dim_CostCenter'[Segment ID Desc], 'Dim_CostCenter'[Subsegment ID Desc] ) VAR __DS0Core = SelectColumns( SUMMARIZECOLUMNS( 'Dim_Acc'[GEN_MEMBER3_DESC], 'Dim_Acc'[GEN_MEMBER4_DESC], 'Dim_Acc'[GEN_MEMBER4_ID], 'Dim_Acc'[GEN_MEMBER5_DESC], 'Dim_Acc'[GEN_MEMBER5_ID], 'Dim_Acc'[GEN_MEMBER6_DESC], 'Dim_Acc'[GEN_MEMBER6_ID], 'Dim_Acc'[GEN_MEMBER7_DESC], 'Dim_Acc'[GEN_MEMBER7_ID], 'Dim_Acc'[GEN_MEMBER8_DESC], 'Dim_Acc'[GEN_MEMBER8_ID], 'Dim_Acc'[GEN_MEMBER9_DESC], 'Dim_Acc'[GEN_MEMBER9_ID], 'Dim_Acc'[GEN_MEMBER10_DESC], 'Dim_CostCenter'[Segment ID Desc], " + Parameters!CC_Group.Value + ", __DS0FilterTable, __DS0FilterTable2, __DS0FilterTable3, __DS0FilterTable4, __DS0FilterTable5, ""Actuals_MTD"", 'Financial_Measures'[Actuals MTD] ), ""ACC_3"", 'Dim_Acc'[GEN_MEMBER3_DESC], ""ACC_4"", 'Dim_Acc'[GEN_MEMBER4_DESC], ""CFIELD"", " + Parameters!CC_Group.Value + ", ""Actuals"", [Actuals_MTD] ) EVALUATE __DS0Core "