Forum Discussion
Combine Sum two value in one column
Hi can anyone help me correct my calculated column, i want the sum of remaining of group1 and 2 on my column. Show error when i try to used below.
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 ) )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.
4 Replies
- Jihwan_KimSuper User
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 ) )- AllanBercesPost Prodigy
Hi Jihwan_Kim thank you very much working as i need
- Poojara_D12Super User
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.
- Ashish_MathurSuper User
Hi,
Share some data to work with and show the expected result. Share data in a format that can be pasted in an MS Excel file.