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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Mkrishna
Helper III
Helper III

Help me to find the total for Measure greater than 0

Hello,

I have written a dax code. 
My aim is to count all the store number that has value greater than 0 as per the condition specified by the STORE variable. But I am not able to produce the retyurn statement
The DAX Code that I have written is as follows:


Measure = 

 

VAR _Reference_Date = MAX('Date'[Date])
VAR _Previous_Dates = DATESINPERIOD(
    'Previous Date'[Date],
    _Reference_Date,
    -3,
    MONTH
)
VAR Customers = VALUES('Data'[Store Number])
VAR MaxDate = MAXX(
    FILTER(
        ALL('Main Table'),
        'Main Table'[Store Number] = MAX('Data'[Store Number]) &&
        'Main Table'[Visit Date] IN _Previous_Dates
    ),
    'Main Table'[Visit Date]
)
VAR STORE =
CALCULATE(
    COUNTROWS(
        FILTER(
            'Main Table',
            'Main Table'[Store Number] = MAX('Data'[Store Number]) &&
            'Main Table'[Visit Date] = MaxDate &&
            'Main Table'[Brand] = "Pepsi"
        )
    ),
    REMOVEFILTERS('Date'),
    KEEPFILTERS(_Previous_Dates),
    USERELATIONSHIP('Date'[Date], 'Previous Date'[Date])
)

The return statement that I am using is 
RETURN if(store>0,1,0).

But this return statement gives me all the stores in customers. But I only want to count the stores whose STORE >0. 

Mkrishna_1-1698658441745.png

 

I should get the Total 5 as these many store has Measure >1 but I am getting 7.  I am also getting Total as 1 instead of 5. Please do help


1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Mkrishna ,

Please try:

RETURN SUMX(VALUES('Main Table'[Store Number]),IF(store>0,1,0))

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

3 REPLIES 3
Arpitb12
Helper I
Helper I

Try this 

Return CALCULATE(
IF(STORE > 0, 1, 0),
FILTER(Customers, STORE > 0)
)

Anonymous
Not applicable

Hi @Mkrishna ,

Please try:

RETURN SUMX(VALUES('Main Table'[Store Number]),IF(store>0,1,0))

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Mkrishna
Helper III
Helper III

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors