Forum Discussion
Combine Sum two value in one column
- 10 months ago
Hi,
I am not sure how the expected result looks like, but please try something like below, and please check whether it works.
Thank you.
TA_Total_Column_Remaining = VAR CurrentDate = TODAY () VAR CurrentGroup = { "Group01", "Group02" } RETURN CALCULATE ( SUM ( 'Table'[Remaining] ), FILTER ( 'Table', 'Table'[PlanDate] = CurrentDate && 'Table'[Trade] IN CurrentGroup ) ) - 10 months ago
Hi AllanBerces
The error in your DAX formula occurs because of how you are using the variable CurrentGroup and the IN operator. In DAX, you can’t assign a logical expression like 'Table'[Trade] IN {"Group01", "Group02"} to a variable and then later compare a column directly to that variable — it results in an invalid data type or logical context error. Also, using CALCULATE inside a calculated column can behave unexpectedly, since it changes the evaluation context for each row, not for an aggregated total. To correctly get the sum of the ‘Remaining’ column for only Group01 and Group02 on the same PlanDate as the current row, you can rewrite your formula like this:
TA_Total_Column_Remaining = VAR CurrentDate = 'Table'[PlanDate] RETURN CALCULATE( SUM('Table'[Remaining]), FILTER( 'Table', 'Table'[PlanDate] = CurrentDate && 'Table'[Trade] IN {"Group01", "Group02"} ) )In this corrected version, the variable CurrentDate stores the row’s PlanDate, and the FILTER function checks for rows in the table that share that same date and belong to Group01 or Group02. The SUM inside CALCULATE then adds up the “Remaining” values for those matching rows. This ensures that for each row in your table, the calculated column correctly displays the total “Remaining” amount for both groups combined for that specific date.
Hi AllanBerces
The error in your DAX formula occurs because of how you are using the variable CurrentGroup and the IN operator. In DAX, you can’t assign a logical expression like 'Table'[Trade] IN {"Group01", "Group02"} to a variable and then later compare a column directly to that variable — it results in an invalid data type or logical context error. Also, using CALCULATE inside a calculated column can behave unexpectedly, since it changes the evaluation context for each row, not for an aggregated total. To correctly get the sum of the ‘Remaining’ column for only Group01 and Group02 on the same PlanDate as the current row, you can rewrite your formula like this:
TA_Total_Column_Remaining =
VAR CurrentDate = 'Table'[PlanDate]
RETURN
CALCULATE(
SUM('Table'[Remaining]),
FILTER(
'Table',
'Table'[PlanDate] = CurrentDate &&
'Table'[Trade] IN {"Group01", "Group02"}
)
)
In this corrected version, the variable CurrentDate stores the row’s PlanDate, and the FILTER function checks for rows in the table that share that same date and belong to Group01 or Group02. The SUM inside CALCULATE then adds up the “Remaining” values for those matching rows. This ensures that for each row in your table, the calculated column correctly displays the total “Remaining” amount for both groups combined for that specific date.