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
DikshaJaiswal
New Member

Unable to get Count of stores for a branch which has sale between 0 to 200000 for last 3 month sales

Hi, 

 

I am unable to get Count of stores which satisfy condition on last 3 months sales.

I have below dataset Table1:

CountryMonth (Real)Day Date (Real)Distributor ID Branch IDDistributor BranchStore IDStore NameSales
INDIA2022M1210-12-2022 00:0096763582034234672ABCV00165TMP102727.2727
INDIA2022M1224-12-2022 00:0096763582034234672ABCV00165TMP144090.9091
INDIA2023M0225-02-2023 00:0096763582034234672ABCV00165TMP936.3637
INDIA2023M0211-02-2023 00:0096763582034234672ABCV00165TMP2200.0002
INDIA2022M1112-11-2022 00:0096763582034234672ABCV00165TMP11955.4547
INDIA2022M0110-01-2022 00:0088734322009835247ABCV00165QRS94754.9874
INDIA2022M0124-01-2022 00:0088734322009835247ABCV00165QRS1090.9091
INDIA2023M0225-02-2023 00:0088734322009835247ABCV00165QRS936.3637
INDIA2023M0211-02-2023 00:0088734322009835247ABCV00165QRS22700.0002
INDIA2022M1212-12-2022 00:0088734322009835247ABCV00165QRS11545.4547



I have to calculate last 3 closed months sales. For e.g., if I select any date in february, it should return sales sum of Jan, Dec, Nov for that store. I created last 3 closed months sales measure which is working fine :

Last 3 Month Sales test = CALCULATE(SUM('Table1'[Sales]),DATESINPERIOD('Calendar Table'[Date],ENDOFMONTH(DATEADD('Calendar Table'[Date],-1,MONTH)),-3,MONTH)).
Here, Calendar Date is my Date Table which has one to many relationship single direction with 'Table1'.

After calculating last 3 months sales, I have to use below conditions to calculates count of stores for a branch:
Store Count: if(Last 3 Month Sales test>=0,if(Last 3 Month Sales test<=200000,DISTINCTCOUNT('Table1','Table1'[Store Name])))

Above measure(Store Count), is returning blank().

Can anyone help to calculate count of stores for a branch which has last 3 closed months store sales between 0 to 20000.

1 ACCEPTED SOLUTION
v-stephen-msft
Community Support
Community Support

Hi @DikshaJaiswal ,

 

I modified the measures as follows.

Last 3 Month Sales test =
VAR _sel =
    SELECTEDVALUE ( 'Calendar Table'[Date] )
VAR _date1 =
    EOMONTH ( _sel, -1 )
VAR _date2 =
    EOMONTH ( _sel, -4 ) + 1
VAR _sum =
    CALCULATE (
        SUM ( Table1[Sales] ),
        FILTER (
            ALLSELECTED ( Table1 ),
            [Store Name] = MAX ( 'Table1'[Store Name] )
                && [Day Date (Real)] <= _date1
                && [Day Date (Real)] >= _date2
        )
    )
RETURN
    _sum
Count =
CALCULATE (
    DISTINCTCOUNT ( Table1[Store Name] ),
    FILTER (
        ALLSELECTED ( Table1 ),
        [Last 3 Month Sales test] <= 200000
            && [Last 3 Month Sales test] >= 0
    )
)

vstephenmsft_0-1678863046965.png

The dates of the slicer come from the [Calendar Date] table, which is not related to the primary table.

You can download my attachment for more details.

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

1 REPLY 1
v-stephen-msft
Community Support
Community Support

Hi @DikshaJaiswal ,

 

I modified the measures as follows.

Last 3 Month Sales test =
VAR _sel =
    SELECTEDVALUE ( 'Calendar Table'[Date] )
VAR _date1 =
    EOMONTH ( _sel, -1 )
VAR _date2 =
    EOMONTH ( _sel, -4 ) + 1
VAR _sum =
    CALCULATE (
        SUM ( Table1[Sales] ),
        FILTER (
            ALLSELECTED ( Table1 ),
            [Store Name] = MAX ( 'Table1'[Store Name] )
                && [Day Date (Real)] <= _date1
                && [Day Date (Real)] >= _date2
        )
    )
RETURN
    _sum
Count =
CALCULATE (
    DISTINCTCOUNT ( Table1[Store Name] ),
    FILTER (
        ALLSELECTED ( Table1 ),
        [Last 3 Month Sales test] <= 200000
            && [Last 3 Month Sales test] >= 0
    )
)

vstephenmsft_0-1678863046965.png

The dates of the slicer come from the [Calendar Date] table, which is not related to the primary table.

You can download my attachment for more details.

                                                                                                                                                         

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

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.