Forum Discussion
Grouping by a column while doing the calculation inside the DAX.
- 1 year ago
Hi Anonymous ,
To apply your calculation grouped by HsCode, you’ll need to wrap your calculation in SUMX over a grouped table, so each group (by HsCode) calculates independently and then aggregates.
Modified DAX with Grouping by HsCode:
MSR_CBAM_Value_Certificate_Cost_All_Actual = VAR SelectedThresholdType = SELECTEDVALUE('Threshold Unit'[Threshold Unit]) RETURN SUMX( VALUES(CBAM_Value_Volume_Summary[HsCode]), VAR CurrentHsCode = CBAM_Value_Volume_Summary[HsCode] RETURN CALCULATE( ( ( SUM ( CBAM_Value_Volume_Summary[Annex_I_Default_specific_embedded_emissions] ) - ( SUM ( CBAM_Value_Volume_Summary[CBAM_Benchmark] ) * ( MAX ( CBAM_Value_Volume_Summary[FactorPercentage] ) / 100 ) ) ) * ( SUM ( CBAM_Value_Volume_Summary[ImportVolume] ) * MAX ( CBAM_Value_Volume_Summary[Annual_Factor] ) ) ) * [MSR_CBAM_Threshold_Value_Price_Actual], FILTER ( CBAM_Value_Volume_Summary, CBAM_Value_Volume_Summary[HsCode] = CurrentHsCode && CBAM_Value_Volume_Summary[TotalCustomsValue] > [MSR_CBAM_Threshold_Value_Price_Actual] && CBAM_Value_Volume_Summary[ThresholdType] = SelectedThresholdType && CBAM_Value_Volume_Summary[Year] = MAX(CBAM_Value_Volume_Summary[Year]) ) ) )
This is a DAX question, so please create a post in the DAX forum
And please make a clearere explanantion of the issue you are facing (show us the visual with the undesired result) and the result you would like to have.
Also,
Please include, in a usable format, not an image, a small set of rows for each of the tables involved in your request and show the data model in a picture, so that we can import the tables in Power BI and reproduce the data model. The subset of rows you provide, even is just a subset of the original tables, must cover your issue or question completely. Do not include sensitive information and do not include anything that is unrelated to the issue or question. Please show the expected outcome based on the sample data you provided and make sure, in case you show a Power BI visual, to clarify the columns used in the grouping sections of the visual.
Need help uploading data? click here
Want faster answers? click here