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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

count if for a measure

I have a visual like this:

Dateconvert_number
Dec5
Jan22
Feb12

convert_number is a measure that counts customers based on conditions

 

I have two other measures that calculates the average sales before event, and the average sales  after.

 

I would like to count how many customers of convert_number have increased average sales.

 

e.g. countif(sales after - sales before) > 0

 

Obviously this doesn't work, I tried using count and countA but they need tables, could someone come up with a solution so my visual would be like this:

Dateconvert_numberincreased sales
Dec53
Jan2217
Feb129

 

Thanks a lot!

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

@Anonymous 
Try this code

increased sale =
VAR T1 =
    SUMMARIZE ( ALL ( 'Orders' ), 'Date'[Date] )
VAR T2 =
    ADDCOLUMNS (
        T1,
        "@Count", [convert_number],
        "@SalesBefore", [Sales Before],
        "@SalesAfter", [Sales After]
    )
VAR T3 =
    FILTER ( T2, [@SalesAfter] > [@SalesBefore] )
RETURN
    SUMX ( T3, [@Count] )

View solution in original post

5 REPLIES 5
tamerj1
Super User
Super User

@Anonymous 
Try this code

increased sale =
VAR T1 =
    SUMMARIZE ( ALL ( 'Orders' ), 'Date'[Date] )
VAR T2 =
    ADDCOLUMNS (
        T1,
        "@Count", [convert_number],
        "@SalesBefore", [Sales Before],
        "@SalesAfter", [Sales After]
    )
VAR T3 =
    FILTER ( T2, [@SalesAfter] > [@SalesBefore] )
RETURN
    SUMX ( T3, [@Count] )
tamerj1
Super User
Super User

Hi @Anonymous 
What are the tables invloved? Do you have a Date table? you are slicing by Month right? From which table? 
However, you may try somthing like this

increased sale =
SUMX ( VALUES ( 'Date'[Date] ), IF ( [Sales After] > [Sales Before], 1 ) )
Anonymous
Not applicable

Thank you for the response!

 

Only the order table is involved. I have a date table. I am slicing it by month from the date table. 

 

I tried the solution but it returns a static number that's the same for every month.

Hi, @Anonymous 

Could you please tell me whether your problem has been solved?

If yes, you could accept the helpful answer as solution.

If you still need help, please share a sample file for further research

Best Regards,
Community Support Team _ Eason

Noted

can you please provide the code of the three Measures?

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.