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
JolienR
Helper II
Helper II

DAX Calculate datesinperiod and filter

I'm trying to count the number of customers in the period 12-6 months ago, however I only want to count the max date per customer. I have the following formula, however this is not working: 

MaxDate/Customer12-6Month =
VAR _MaxDate = max('Calendar'[Date])
VAR _StartDate = MINX(FILTER(DATESINPERIOD('Calendar'[Date]; _maxDate; -6; MONTH ); 'Calendar'[Date]);'Calendar'[Date])
VAR _ID = MAX('table'[ID_CUSTOMER_GUID])
RETURN
CALCULATE(DISTINCTCOUNTNOBLANK('table'[ID_CUSTOMER_GUID]);
FILTER('table';table'[DATES]=[LastDate12-6Month]);
DATESINPERIOD('Calendar'[Date];_StartDate;-6;MONTH))
JolienR_0-1680516864797.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @JolienR ,

Have a try.

easure = VAR _6MONTH=EDATE([LAST DATE],-6)
VAR _12MONTH=EDATE([LAST DATE],-12)
 VAR _1= CALCULATE(MAX('Table'[dates]),FILTER(ALL('Table'),'Table'[customer]=SELECTEDVALUE('Table'[customer])&&'Table'[dates]<=_6MONTH&&'Table'[dates]>=_12MONTH))
RETURN
IF(_1=SELECTEDVALUE('Table'[dates]),_1,BLANK())

If it does not help, please provide a screenshot of the required output for the image you provided.

 

Best Regards
Community Support Team _ Rongtie

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 @JolienR ,

Do you want to calculate data from six months ago to one year ago or from six months to one year in the future?

What do you want the output to look like in the picture you gave?Do you wish to calculate it 6-12 months ago based on the selected date?

 

Please have a try.

Measure = VAR _6MONTH=EDATE([LAST DATE],6)
VAR _12MONTH=EDATE([LAST DATE],12)
 VAR _1= CALCULATE(MAX('Table'[dates]),FILTER(ALL('Table'),'Table'[customer]=SELECTEDVALUE('Table'[customer])&&'Table'[dates]>=_6MONTH&&'Table'[dates]<=_12MONTH))
RETURN
IF(_1=SELECTEDVALUE('Table'[dates]),_1,BLANK())

vrongtiepmsft_0-1680834755939.png

 

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

 

Thanks for your respons. 
I want to DISTINCTCOUNT the number of customers 6 to 12 months ago. However, I only want to count the last visitdate per customer. 

Anonymous
Not applicable

Hi @JolienR ,

Have a try.

easure = VAR _6MONTH=EDATE([LAST DATE],-6)
VAR _12MONTH=EDATE([LAST DATE],-12)
 VAR _1= CALCULATE(MAX('Table'[dates]),FILTER(ALL('Table'),'Table'[customer]=SELECTEDVALUE('Table'[customer])&&'Table'[dates]<=_6MONTH&&'Table'[dates]>=_12MONTH))
RETURN
IF(_1=SELECTEDVALUE('Table'[dates]),_1,BLANK())

If it does not help, please provide a screenshot of the required output for the image you provided.

 

Best Regards
Community Support Team _ Rongtie

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

JolienR
Helper II
Helper II

Hi @Anonymous ,
Thank you for your response, however it does not help.

One customer can have visit our locations multiple times in the selected period. However, I just want the count for each customer only the last visit in the period from 12 to 6 months ago. I have attached a test file. Hopefully it is clear lik this:

JolienR_1-1680778617389.png

 

I have a working measure for the current selected month, namely:

CALCULATE(DISTINCTCOUNTNOBLANK('table'[ID_CUSTOMER_GUID]);
FILTER('table';table'[DATES]=[LastDate])).
 

However for the period from 12-6 months the combination Filter && Dates in period is not working. 

CALCULATE(DISTINCTCOUNTNOBLANK('table'[ID_CUSTOMER_GUID]);
FILTER('table';table'[DATES]=[LastDate12-6Month]);
DATESINPERIOD('Calendar'[Date];_StartDate;-6;MONTH))

 

Anonymous
Not applicable

Hi @JolienR ,

Please have a try.

measure =
VAR _1 =
    TODAY ()
VAR _12monthago =
    EDATE ( _1, -12 )
VAR _6monthage =
    EDATE ( _1, -6 )
RETURN
    CALCULATE (
        MAX ( calendar[date] ),
        FILTER (
            ALL ( table ),
            table[date] >= _12monthago
                && table[date] <= _6monthage
                && table[customer] = SELECTEDVALUE ( table[customer] )
        )
    )

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

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

 

Helpful resources

Announcements
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!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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