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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
klopdaddy
Regular Visitor

Virtual Table Row Count with Boolean Expression

Hello-

I am tryint to count the # of events by comparing two calculated measures and returning the count of only those rows that meet the condition. I've been trying via the DAX statement and creation of a virtual tabkle from a much larger SQL table. The below expression appears to ignore the results of the comparision and return all rows of the virtual table.

When i substitute the COUNTAX operator with a SUMX on the same calculated column (w/o the comparison) the statement returns the correct value. Any suggestions would be greatly appreciated.

 

Event_Over_Budget_Count = CALCULATE(
COUNTAX(
SUMMARIZE(
table_A, table_A[eventName],
"Spend Ratio", DIVIDE
CALCULATE(
SUM (table_A[eventspend]), DATESINPERIOD(table_A[date], MAX(table_A[date]), -1, day)),
DIVIDE( MAX( table_A[budgetamt]), DATEDIFF(MIN(table_A[eventStartDate]), MAX(table_A[event[EndDate]), DAY) + 1))),
([Spend Ratio] >1 )), lookup_Table[event_active_flag] = "Y")

1 ACCEPTED SOLUTION

That worked with the help of an if statement in my virtual column to create the boolean output to sum.

Thanks!

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

@klopdaddy 

COUNTX won't work with boolean condition. Boolean condition will return either one or zero and CONTX will count booth. 
As you've already mentioned in your post, SUMX will provide perfecr count of "1". 

Thanks for the quick response. Do you have any suggestions on how to count the number of rows of the virtual table that meet the conditions specified? I don't want the sum of the values from the expression i want to be able to compare each value to a criteria (in this case '1') and return a count of only those rows that meet the requirement. Do you know of a better strategy?

Thanks,
Sean

@klopdaddy 

Just replace CONTX with SUMX to cout the trure condition. Boolean condition can be summed. The sum would be the count of true cases as true is translated to 1. 

That worked with the help of an if statement in my virtual column to create the boolean output to sum.

Thanks!

@klopdaddy 

If you find my reply helpful you may consider selecting it as acceptable solution. Thank you and have a great weekend!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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