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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
xxyb720
Frequent Visitor

DAX function for calculations meeting certain conditions

The calculation I want to do is count(if(group = A))/total count of group - count(if(group = C))/total count of group by region or by state depending on business needs. I am creating a new column in the visual so I can calculate the result based on different dimensions.

 

Here's what the original data looks like:

groupregionstate
A1CA
A1CA
B1CA
C1CA

 

The desired result looks like this:

By region:

regionresult
125%

* 25% = count of A/total count of group - count of C/total count of group

 

By state:

stateresult
CA25%

 

I've been researching around but didn't see anything that's close to what I need. Please help with the DAX function. Thanks in advance!

1 ACCEPTED SOLUTION
v-henryk-mstf
Community Support
Community Support

Hi @xxyb720 ,

 

According to your description, you can refer to the following test results:

Count all =
VAR Count_A =
    CALCULATE ( COUNTROWS ( 'Date' ), 'Date'[group] = "A" )
VAR Count_C =
    CALCULATE ( COUNTROWS ( 'Date' ), 'Date'[group] = "C" )
RETURN
    DIVIDE ( ( Count_A - Count_C ), COUNTROWS ( 'Date' ) )

 

vhenrykmstf_0-1652176586716.png

 

If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
v-henryk-mstf
Community Support
Community Support

Hi @xxyb720 ,

 

According to your description, you can refer to the following test results:

Count all =
VAR Count_A =
    CALCULATE ( COUNTROWS ( 'Date' ), 'Date'[group] = "A" )
VAR Count_C =
    CALCULATE ( COUNTROWS ( 'Date' ), 'Date'[group] = "C" )
RETURN
    DIVIDE ( ( Count_A - Count_C ), COUNTROWS ( 'Date' ) )

 

vhenrykmstf_0-1652176586716.png

 

If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.


Best Regards,
Henry


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Ashish_Mathur
Super User
Super User

Hi,

Write these measures:

Count all = countrows(Data)

Count of A = calculate([Count all],Data[Group]="A")

Count of C = calculate([Count all],Data[Group]="C")

Ratio = divide(([Count of A]-[Count of C]),[count all])


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.