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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

Dax codes for conditions and filters during calcuations

Hi,

I am doing some calculations in Power BI with DAX. The calculations should consider the values which can be selected in a filter which is coming from a column. Let's call it H which can have 10 values, but for me only values 1,2,3 and 4 are important. I am working on a formula(let's call it C) which is suppose to calculate a value when values 1 or 2 or 3 is selected(done in a calculated measure called A), a formula when only 4 is selected(in a calulated measure called B) and addition of the both formulas if 4 and either one of the 1,2 or 3 is selected. Of course values of 1,2 or 3 changes the result of the first formula. The formulas currently look like this:

 

A= calculate(D, AND(H<>"4", H=selectedvalue(H) ) )
B=calculate(E, H="4")

 

D and E values formulas are very like A and B respectively but they calculate the value of other calcualted measures using the same conditions.

 

For C I am currently using this:

 

step 7 = IF(CONTAINSSTRING( VALUES(H),
                            "4"),
                IF(COUNTROWS(VALUES(H))=1,
                    [A],
                    [A]+[B]
                    ),
                [B]
            )
I have 2 issues:
1- I am not sure that my conditions using the selectedvalue is correct or not?
2- I have issues with the numbers of A and B when selecting more than one value in the slicer for H.

 

What is my problem here?

1 REPLY 1
lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.powerbi.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-...
Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.