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]) ) ) )
Hi Anonymous,
Thanks for reaching out to the Microsoft fabric community forum.
I understand that your existing calculation is working at a total level and not grouping by HsCode, which is now required for accurate per-category aggregation. You're essentially looking to apply the calculation individually per HsCode and then aggregate the result across all HsCodes.
You are absolutely on the right track and kindly go through the suggested approaches shared by Anonymous
and rohit1991 in the thread and check if your issue can be resolved.
I would also take a moment to thank rohit1991, Anonymous and FBergamaschi for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference
If I misunderstand your needs or you still have problems on it, please feel free to let us know.
Best Regards,
Hammad.
- Anonymous1 year agoNot applicable
Hi Anonymous,
As we haven’t heard back from you, so just following up to our previous message. I'd like to confirm if you've successfully resolved this issue or if you need further help.
If yes, you are welcome to share your workaround so that other users can benefit as well. And if you're still looking for guidance, feel free to give us an update, we’re here for you.
Best Regards,
Hammad.
- Anonymous1 year agoNot applicable
Hi Anonymous,
Hope everything’s going smoothly on your end. As we haven’t heard back from you, so I wanted to check if the issue got sorted.
Still stuck? No worries just drop us a message and we can jump back in on the issue.Best Regards,
Hammad.
- Anonymous1 year agoNot applicable
Anonymous I got some solution we can close this