Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Mehef_koul
New Member

Dax calculation help

Hi @everyone,

I would like to calculate a measure to add the values of rows. For example I have a slicer [subject] containing {subject1,subject2,subject3 etc...} when I deactivate Subject 3, the value of Subject 3 is added to the value of Subject 1.

subject value
subject 11
subject 21
subject 31
subject 41
subject 51
subject 61
1 ACCEPTED SOLUTION
johnbasha33
Super User
Super User

@Mehef_koul 

To achieve this, you can create a measure in Power BI that dynamically adjusts the values based on the selection made in the slicer. You can use the SWITCH function along with the ISFILTERED function to determine which subject(s) are selected in the slicer, and then calculate the sum accordingly. Here's how you can do it:

```DAX
Total Value =
VAR SelectedSubjects =
VALUES ( 'YourTable'[subject] )
RETURN
SWITCH (
TRUE (),
COUNTROWS ( SelectedSubjects ) = 0, SUM ( 'YourTable'[value] ), -- If no subject selected, show total value
COUNTROWS ( SelectedSubjects ) > 1, BLANK (), -- If more than one subject selected, show blank (optional)
SELECTEDVALUE ( 'YourTable'[subject] ), -- If only one subject selected, show the value of that subject
CALCULATE (
SUM ( 'YourTable'[value] ),
ALL ( 'YourTable'[subject] ),
'YourTable'[subject] = SELECTEDVALUE ( 'YourTable'[subject] )
)
)
```

Replace `'YourTable'` with the actual name of your table, and `'subject'` and `'value'` with the names of your subject and value columns, respectively.

Here's how the measure works:

- It first checks if any subject is selected. If no subject is selected, it shows the total value.
- If more than one subject is selected, it shows blank (you can remove this line if you want to display something else in this case).
- If only one subject is selected, it shows the value of that subject.
- If a single subject is selected, it calculates the sum of values for that subject only.

This measure should give you the desired result of dynamically adjusting the values based on the selection made in the slicer. Adjust it as needed based on your specific requirements and data model.

Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

View solution in original post

1 REPLY 1
johnbasha33
Super User
Super User

@Mehef_koul 

To achieve this, you can create a measure in Power BI that dynamically adjusts the values based on the selection made in the slicer. You can use the SWITCH function along with the ISFILTERED function to determine which subject(s) are selected in the slicer, and then calculate the sum accordingly. Here's how you can do it:

```DAX
Total Value =
VAR SelectedSubjects =
VALUES ( 'YourTable'[subject] )
RETURN
SWITCH (
TRUE (),
COUNTROWS ( SelectedSubjects ) = 0, SUM ( 'YourTable'[value] ), -- If no subject selected, show total value
COUNTROWS ( SelectedSubjects ) > 1, BLANK (), -- If more than one subject selected, show blank (optional)
SELECTEDVALUE ( 'YourTable'[subject] ), -- If only one subject selected, show the value of that subject
CALCULATE (
SUM ( 'YourTable'[value] ),
ALL ( 'YourTable'[subject] ),
'YourTable'[subject] = SELECTEDVALUE ( 'YourTable'[subject] )
)
)
```

Replace `'YourTable'` with the actual name of your table, and `'subject'` and `'value'` with the names of your subject and value columns, respectively.

Here's how the measure works:

- It first checks if any subject is selected. If no subject is selected, it shows the total value.
- If more than one subject is selected, it shows blank (you can remove this line if you want to display something else in this case).
- If only one subject is selected, it shows the value of that subject.
- If a single subject is selected, it calculates the sum of values for that subject only.

This measure should give you the desired result of dynamically adjusting the values based on the selection made in the slicer. Adjust it as needed based on your specific requirements and data model.

Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors