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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

countif a comparative condition is met

Hi everyone
I need your help with the following problem:
I have two tables, in one these the goals of visits by seller to their customers and in the other are the visits made daily, both related.
The idea is that the percentage of visit compliance never exceeds 100%, regardless of whether you have made more views than planned.
So, what we are looking for is a formula that counts the visits made but the result does not exceed the number of the goal that is in the other table.Imagen1.png

 

I thank you for what you can help me

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

Add these two columns in table 1

	visitaReales= countx(filter(table2,table1[vendedor]=table2[vendedor]),table2[ClienteCod])
	VisitaMax=if(table1[meta]<=table1[visitaReales],table1[meta],table1[visitaReales])

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

View solution in original post

v-yiruan-msft
Community Support
Community Support

Hi @Anonymous,

According to the information in your case, I just create one sample PBIX file. You can create one measure just like in sample file:

  1. Get the current customer
  2. Calculate numbers of current customer visit
  3. If the number of user visits is greater than the goal number , it is counted as the goal number. Otherwise it is counted as the actual number of visits. Divide the number of final visits by the goal number to calculate the percentage of visits   Count if condition.JPG

maxVisit = VAR c =

    MAX ( 'Visits'[Customer] )

VAR s =

    COUNTAX ( 'Visits', 'Visits'[Customer] = c )

VAR vgoal =

    CALCULATE (

        MAX ( 'VisitGoal'[Goals] ),

        FILTER ( 'VisitGoal', 'VisitGoal'[Customer] = c )

    )

RETURN

   DIVIDE( IF ( s < vgoal, s, vgoal ),vgoal)

 

Best Regards

Rena

Community Support Team _ Rena
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-yiruan-msft
Community Support
Community Support

Hi @Anonymous,

According to the information in your case, I just create one sample PBIX file. You can create one measure just like in sample file:

  1. Get the current customer
  2. Calculate numbers of current customer visit
  3. If the number of user visits is greater than the goal number , it is counted as the goal number. Otherwise it is counted as the actual number of visits. Divide the number of final visits by the goal number to calculate the percentage of visits   Count if condition.JPG

maxVisit = VAR c =

    MAX ( 'Visits'[Customer] )

VAR s =

    COUNTAX ( 'Visits', 'Visits'[Customer] = c )

VAR vgoal =

    CALCULATE (

        MAX ( 'VisitGoal'[Goals] ),

        FILTER ( 'VisitGoal', 'VisitGoal'[Customer] = c )

    )

RETURN

   DIVIDE( IF ( s < vgoal, s, vgoal ),vgoal)

 

Best Regards

Rena

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

Add these two columns in table 1

	visitaReales= countx(filter(table2,table1[vendedor]=table2[vendedor]),table2[ClienteCod])
	VisitaMax=if(table1[meta]<=table1[visitaReales],table1[meta],table1[visitaReales])

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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