cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jsabo Regular Visitor
Regular Visitor

Measure for count of last 7 days

I am looking for DAX that will count the number of Visits for the given time frame (today looking 7 days back). I have tried the below, but it is giving me an error regarding duplicate dates. Any ideas?

 

Requested Last 7 Days = CALCULATE (
        COUNT ( 'Active Assignments'[assignment_seq] ),
        DATESINPERIOD ( 'Active Assignments'[date_requested], LASTDATE ( 'Active Assignments'[date_requested] ), -7, DAY )
    )
1 ACCEPTED SOLUTION

Accepted Solutions
jsabo Regular Visitor
Regular Visitor

Re: Measure for count of last 7 days

@MrPowerBIPro, thanks. Below is the error:

 

 

Error Message:
MdxScript(Model) (3, 9) Calculation error in measure 'Active Assignments'[Requested Last 7 Days]: A date column containing duplicate dates was specified in the call to function 'DATESINPERIOD'. This is not supported.

 

Again, I just wanted to count the number of Assignment IDs (assignment_seq) opened in the last 7 days (using the date_requested field).

 

EDIT: was overthinking it, found a solution:

 

Requested Last 7 Days = CALCULATE(
        DISTINCTCOUNT('Active Assignments'[assignment_seq]),
        FILTER(ALL('Active Assignments'), 'Active Assignments'[date_requested] >= TODAY()-7)
)

View solution in original post

5 REPLIES 5
MrPowerBIPro Regular Visitor
Regular Visitor

Re: Measure for count of last 7 days

Can you copy the error here?

 

Enemy of can't
www.mrpowerbi.pro
jsabo Regular Visitor
Regular Visitor

Re: Measure for count of last 7 days

@MrPowerBIPro, thanks. Below is the error:

 

 

Error Message:
MdxScript(Model) (3, 9) Calculation error in measure 'Active Assignments'[Requested Last 7 Days]: A date column containing duplicate dates was specified in the call to function 'DATESINPERIOD'. This is not supported.

 

Again, I just wanted to count the number of Assignment IDs (assignment_seq) opened in the last 7 days (using the date_requested field).

 

EDIT: was overthinking it, found a solution:

 

Requested Last 7 Days = CALCULATE(
        DISTINCTCOUNT('Active Assignments'[assignment_seq]),
        FILTER(ALL('Active Assignments'), 'Active Assignments'[date_requested] >= TODAY()-7)
)

View solution in original post

MrPowerBIPro Regular Visitor
Regular Visitor

Re: Measure for count of last 7 days

@jsabo That's a Good news.

 

See this link to found more:

 

 

https://community.powerbi.com/t5/Desktop/DATESBETWEEN-Date-and-Time-Field/td-p/17462

 

 

Regards

Mostafa

Enemy of can't
www.mrpowerbi.pro
Nischal Regular Visitor
Regular Visitor

Re: Measure for count of last 7 days

There is some error in this method, I should get 0 instead I am getting 3......

 

 

week=CALCULATE(DISTINCTCOUNT(survey_reports[mobile]),DATESINPERIOD(survey_reports[date],LASTDATE(survey_reports[date]),-7,DAY))

 

 

Nischal Regular Visitor
Regular Visitor

Re: Measure for count of last 7 days

Requested Last 7 Days = CALCULATE (
DISTINCTCOUNT ( survey_reports[responseId] ),
DATESINPERIOD ( date1[Date] ,LASTDATE(date1[Date] ), -7, DAY )
)

 

 

it's giving me a blank instead of value

Helpful resources

Announcements
Ask Amanda Anything Q&A

Ask Amanda Anything Q&A

Learn the answers to some of the questions asked during the Amanda Triple A event.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 72 members 1,109 guests
Please welcome our newest community members: