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! Request now

Reply
Anonymous
Not applicable

dax

p1m =
CALCULATE(
    DISTINCTCOUNT(PSR[customer_code]),
    FILTER(
        VALUES(PSR[customer_code]),
        [sum of ret] > 0
    )
)

this is a measure that calculates distinct customer count of customers whose sum of retailing is >0.
i want to calculate another measure that shows distinct count of customer of this month+last 2 month in the current month.
eg count of november would be nov+oct+sept. similarly count of dec would be dec+nov+oct.
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

I suggest you to create a "DimDate" table to help calculation.

DimDate = 
VAR _CALENDAR =
    CALENDARAUTO()
RETURN
    ADDCOLUMNS (
        _CALENDAR,
        "Year", YEAR ( [Date] ),
        "Month", MONTH ( [Date] ),
        "MonthName", FORMAT ( [Date], "MMMM" ),
        "RANKX",
            RANKX ( _CALENDAR, YEAR ( [Date] ) * 100 + MONTH ( [Date] ),, ASC, DENSE )
    )

Measure:

Sum 3 month count = 
VAR _SUMMARIZE =
    SUMMARIZE (
        ALL ( DimDate ),
        DimDate[Year],
        DimDate[MonthName],
        DimDate[RANKX],
        "P1M", [p1m]
    )
RETURN
    SUMX (
        FILTER (
            _SUMMARIZE,
            [RANKX]
                > MAX ( DimDate[RANKX] ) - 3
                && [RANKX] <= MAX ( DimDate[RANKX] )
        ),
        [P1M]
    )

Result is as below.

vrzhoumsft_0-1701073919213.png

 

Best Regards,
Rico Zhou

 

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

5 REPLIES 5
Anonymous
Not applicable

Hi @Anonymous ,

 

I suggest you to create a "DimDate" table to help calculation.

DimDate = 
VAR _CALENDAR =
    CALENDARAUTO()
RETURN
    ADDCOLUMNS (
        _CALENDAR,
        "Year", YEAR ( [Date] ),
        "Month", MONTH ( [Date] ),
        "MonthName", FORMAT ( [Date], "MMMM" ),
        "RANKX",
            RANKX ( _CALENDAR, YEAR ( [Date] ) * 100 + MONTH ( [Date] ),, ASC, DENSE )
    )

Measure:

Sum 3 month count = 
VAR _SUMMARIZE =
    SUMMARIZE (
        ALL ( DimDate ),
        DimDate[Year],
        DimDate[MonthName],
        DimDate[RANKX],
        "P1M", [p1m]
    )
RETURN
    SUMX (
        FILTER (
            _SUMMARIZE,
            [RANKX]
                > MAX ( DimDate[RANKX] ) - 3
                && [RANKX] <= MAX ( DimDate[RANKX] )
        ),
        [P1M]
    )

Result is as below.

vrzhoumsft_0-1701073919213.png

 

Best Regards,
Rico Zhou

 

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

 

Ahmedx
Super User
Super User

pls try this

 

CURRENT MONTH nov = 
VAR _Start = EOMONTH(TODAY(),-1)+1

VAR _End = EOMONTH(TODAY(),0)
RETURN
CALCULATE([p1m], DATESBETWEEN('Calendar'[Date],_Start,_End)
-------------
Last 1 MONTH Oct = 
VAR _Start = EOMONTH(TODAY(),-2)+1

VAR _End = EOMONTH(TODAY(),-1)
RETURN
CALCULATE([p1m], DATESBETWEEN('Calendar'[Date],_Start,_End)
------------
Last 2 MONTH Sept= 
VAR _Start = EOMONTH(TODAY(),-3)+1

VAR _End = EOMONTH(TODAY(),-2)
RETURN
CALCULATE([p1m], DATESBETWEEN('Calendar'[Date],_Start,_End)

 

Anonymous
Not applicable

Kishore_KVN
Super User
Super User

Hello @Anonymous ,

Firstly create a calendar table and create relationship with your fact table. 

Then use below calculation by modifying table names as per your data.

Cal_Measure =
Var CM = CALCULATE(DISTINCTCOUNT(PSR[customer_code]), Filter(Calendar_Table, 'Calendar_Table'[Month] = Month(Today())))
Var PM = CALCULATE(DISTINCTCOUNT(PSR[customer_code]), Filter(Calendar_Table, 'Calendar_Table'[Month] = Month(Today())-1))
Var PPM = CALCULATE(DISTINCTCOUNT(PSR[customer_code]), Filter(Calendar_Table, 'Calendar_Table'[Month] = Month(Today())-2))
Return
CM+PM+PPM

 

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

Anonymous
Not applicable

not displaying anything

 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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
Top Kudoed Authors