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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
v-cgao-msft
Community Support
Community Support

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)
)

v-cgao-msft
Community Support
Community Support

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
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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