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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
Anonymous
Not applicable

Calculate distinct count only within 6 Months

Hello there

 

This is probably another question for help replacing the COUNTIFS formula with DAX.

 

I've tried a few similar solutions posted on here and even tried Grouping my Table etc but with no success.

 

What I want is to distinct count the PRPcode only within the last 6 months in the table below:

 

 

PRPcpde            JNLCODE        Date

CBL1210067      123                  01/01/2016

CBL1210067      1234                12/01/2015

CBL1210067      12345               05/01/2016

CBL1210067      11235               02/04/2015

 

I.e the answer should be 2

 

In addition I'm also having trouble working out the1/COUNTIFS DAX?? (no date range required)

 

I.e for the above table the value of each row should be 0.25

 

Many thanks in advance for your help!

 

MG

 

 

 

2 ACCEPTED SOLUTIONS
Baskar
Resident Rockstar
Resident Rockstar

Hi MG

 

M = Calculate(DistinctCount(PRPcpde),filter(Date>= Dateadd(Today(),-6,Month))

 

or

 

M = Calculate(DistinctCount(PRPcpde),filter(Date>= Dateadd(max(date),-6,Month))

 

Try this

 

View solution in original post

v-sihou-msft
Microsoft Employee
Microsoft Employee

@Anonymous

 

In this scenario, if you want to distinct count the PRPcode only within the last 6 months, you can create measures with following formulas. To count the PRPcode instead of distinct count, you can replace “DISTINCTCOUNT” with “COUNTA” in following formulas.

 

DistinctCount_Of_PRPcode_Within_Last_6_Months(From Today) =

CALCULATE (

    DISTINCTCOUNT ( Table1[PRPcode] ),

    DATESINPERIOD(Table1[Date], TODAY(), -6, MONTH)

)

 

DistinctCount_Of_PRPcode_Within_Last_6_Months(From Latest Date in Table1) =

CALCULATE (

    DISTINCTCOUNT ( Table1[PRPcode] ),

    DATESINPERIOD(Table1[Date], LASTDATE(Table1[Date]), -6, MONTH)

)

 

For 1/COUNTIFS DAX (no date range required), you can also create a measure with following formula.

1/DistinCount_Of_PBRcode = 1 / DISTINCTCOUNT(Table1[PRPcode])

 

1234.png

 

Regards,

View solution in original post

4 REPLIES 4
v-sihou-msft
Microsoft Employee
Microsoft Employee

@Anonymous

 

In this scenario, if you want to distinct count the PRPcode only within the last 6 months, you can create measures with following formulas. To count the PRPcode instead of distinct count, you can replace “DISTINCTCOUNT” with “COUNTA” in following formulas.

 

DistinctCount_Of_PRPcode_Within_Last_6_Months(From Today) =

CALCULATE (

    DISTINCTCOUNT ( Table1[PRPcode] ),

    DATESINPERIOD(Table1[Date], TODAY(), -6, MONTH)

)

 

DistinctCount_Of_PRPcode_Within_Last_6_Months(From Latest Date in Table1) =

CALCULATE (

    DISTINCTCOUNT ( Table1[PRPcode] ),

    DATESINPERIOD(Table1[Date], LASTDATE(Table1[Date]), -6, MONTH)

)

 

For 1/COUNTIFS DAX (no date range required), you can also create a measure with following formula.

1/DistinCount_Of_PBRcode = 1 / DISTINCTCOUNT(Table1[PRPcode])

 

1234.png

 

Regards,

Anonymous
Not applicable

Thanks to both of you!! Both worked for me! Cheers. Smiley Very Happy

Anonymous
Not applicable

Hi 

 

I'm trying to duplicate the above measure as a new column. 

 

Reason for this is that I want users to See Records within the graph which you cannot currently do with a measure. 

 

I've tried various variations but never get the same figure as the measure. 

 

Any suggestions? 

Baskar
Resident Rockstar
Resident Rockstar

Hi MG

 

M = Calculate(DistinctCount(PRPcpde),filter(Date>= Dateadd(Today(),-6,Month))

 

or

 

M = Calculate(DistinctCount(PRPcpde),filter(Date>= Dateadd(max(date),-6,Month))

 

Try this

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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
Top Kudoed Authors