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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
Alka735
Frequent Visitor

calculating current month sales for only those dealers on which activity performed in L3M

Hii All,

Hope you are doing well.

I need help with a requirement: we want to calculate current-month (or month-wise) sales only for those customers who had activity at their counter in the last 3 completed months.

For example, if April is the current month, only customers with activity between January and March should be considered, and their April sales should be included regardless of whether they had activity in April or not.

Please help me with this question.

I am sharing the sample dataset for 2 tables ,Activity and Sales,we need to consider the customers where activity conducted at "Dealer Counter"
and the final output will be 700(total sales)

Date Customer ID Sales Amount

2026-04-02C001100
2026-04-10C002200
2026-04-12C003150
2026-04-15C004300
2026-04-18C005250
2026-04-20C006400

Date Customer ID Activity Conducted At

2026-01-10C001dealer Counter
2026-02-15C002dealer Counter
2026-03-05C001dealer Counter
2026-03-20C003dealer Counter
2026-01-25C004other
2026-02-10C005dealer Counter
2026-04-05C006dealer Counter

Customer ID April Sales

C001100
C002200
C003150
C005250
1 ACCEPTED SOLUTION

Hi @Alka735 

Can you try this

L3M Active Dealers Current Month Sales =

VAR LastVisibleDate = MAX('Calendar'[Date])

 

VAR Prev3Months = DATESINPERIOD(

'Calendar'[Date],EOMONTH(LastVisibleDate, -1),-3,MONTH)

 

VAR DealerList = CALCULATETABLE(

DISTINCT('Activity'[Dealer ERP Code]),Prev3Months,

'Activity'[Activity Conducted At] = "dealer Counter")

 

RETURN

CALCULATE([TOTAL_SALE],TREATAS(DealerList, 'Sales'[Dealer ERP Code]))

View solution in original post

6 REPLIES 6
Alka735
Frequent Visitor

Thanks @krishnakanth240 ,it's working fine.

You are welcome @Alka735 

pcoley
Solution Supplier
Solution Supplier

@Alka735 Please try with this script:

  • Make sure the relationship between Activity and Sales tables is not active (or use CROSSFILTER if needed), because we want independent filtering.
  • Replace 'Date' with your actual Date table name if using version

 

Dealer Counter Current Month Sales = 

VAR CurrentDate = MAX ( 'Date'[Date] )   // Assuming you have a proper Date table
VAR CurrentMonthStart = STARTOFMONTH ( CurrentDate )
VAR Last3MonthsStart  = EDATE ( CurrentMonthStart, -3 )

VAR QualifyingCustomers = 
    CALCULATETABLE (
        VALUES ( Activity[ID] ),
        Activity[Activity Conducted At] = "dealer Counter",
        Activity[Date] >= Last3MonthsStart,
        Activity[Date] < CurrentMonthStart
    )

RETURN
    CALCULATE (
        SUM ( Sales[Sales Amount] ),
        Sales[ID] IN QualifyingCustomers,
        Sales[Date Customer] >= CurrentMonthStart,
        Sales[Date Customer] < EOMONTH(CurrentMonthStart, 0) + 1
    )

 


I hope this helps.
If so please Mark it as a solution.
Kudos are Welcome!
Murtaza_Ghafoor
Solution Supplier
Solution Supplier

@Alka735 

You need to write a DAX to caluclate this 

Sales_Last3M_ActiveCustomers :=

VAR _currentDate = MAX(Sales[Date])
VAR _fromDate = EOMONTH(_currentDate, -4) + 1
VAR _toDate   = EOMONTH(_currentDate, -1)
VAR _customers =
    CALCULATETABLE (

        VALUES ( Activity[Customer ID] ),

        Activity[Activity Conducted At] = "dealer Counter",

        Activity[Date] >= _fromDate,

        Activity[Date] <= _toDate
    )

RETURN
CALCULATE (

    SUM ( Sales[Sales Amount] ),

    Sales[Customer ID] IN _customers

)

 

Alka735
Frequent Visitor

I am trying with this logic, but not getting correct results,some customers sales are skipped while calculation

 

L3M Active Dealers Current Month Sales = VAR L3M_Dealer_List = CALCULATETABLE( VALUES(DATA1[Dealer ERP Code]), -- Last 3 completed months DATESINPERIOD( 'Calendar'[Date], EOMONTH(MAX('Calendar'[Date]), -1), -3, MONTH ), -- Activity condition DATA1[Activity Conducted At] = "dealer Counter", -- Valid dealer NOT(ISBLANK(DATA1[Dealer ERP Code])) ) RETURN CALCULATE( [TOTAL_SALE], -- Apply only those dealers TREATAS(L3M_Dealer_List, DATA1[Dealer ERP Code]) )

Hi @Alka735 

Can you try this

L3M Active Dealers Current Month Sales =

VAR LastVisibleDate = MAX('Calendar'[Date])

 

VAR Prev3Months = DATESINPERIOD(

'Calendar'[Date],EOMONTH(LastVisibleDate, -1),-3,MONTH)

 

VAR DealerList = CALCULATETABLE(

DISTINCT('Activity'[Dealer ERP Code]),Prev3Months,

'Activity'[Activity Conducted At] = "dealer Counter")

 

RETURN

CALCULATE([TOTAL_SALE],TREATAS(DealerList, 'Sales'[Dealer ERP Code]))

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.