Link to home
Start Free TrialLog in
Avatar of gvamsimba
gvamsimbaFlag for United Kingdom of Great Britain and Northern Ireland

asked on

PowerBI getting data for last 7 days

Hi, I am working on a PowerBI report and I need to do count of customers who made orders in the last 7 days. for Date, i have year,quarter,month and day.

can anyone let me know how to show the count of customers for the last 7 days in power bi ? Many Thanks
Avatar of Tom Farrar
Tom Farrar
Flag of United States of America image

Take a look at the DATEADD function in DAX.  DATEADD (Calendar [Date], -7, Day).  Formula should look something like:

CALCULATE([CustomerCount], DATEADD('Calendar'[Date], -7, Day)).  You would have to fill in yourown field names, and the [CustomerCount] assumes you have a measure called that for customer count.
Avatar of gvamsimba

ASKER

Hi Tom, no I dont have any measure for customercount yet. I just need to create one. I have custid and date column in my dateset and date column has year,quarter,month and day .
I m new to powerbi. can you please let me what exactly I need to do now ? shall I create a new calculated column using the above dax formula ?

Thanks
When you say your dataset, do you mean you have one table with all the data in it?
No, i have imported 5 tables into Powerbi for this report. For customerid and date fields are in one table only. So for this specific calucation to get customers for last 7 days , i can just use this one table.
First create a new measure named CustCount:  =COUNT(Table[CustID]).  Put that in a visual and see if it gives you what you are looking for in customer count.


Your final formula should look something like this:

= CALCULATE([CustCount], DATEADD(Today(), -7, Day))
ASKER CERTIFIED SOLUTION
Avatar of Tom Farrar
Tom Farrar
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
aah ok got you Tom. Do you think its a good idea for me to create a new table for Measures so that I can create all the measures in this table ?

I have created the below 2 measures in the new meaures table. can you please confirm if this is right ?
Many Thanks Tom.

DistinctAccountsCount = DISTINCTCOUNT(Opportunity[Accountid]

Last7daysAccounts = CALCULATE([DistinctAccountsCount], DATEADD('Opportunity'[Reservation_Cancelled_Date__c], -7, Day))
"aah ok got you Tom. Do you think its a good idea for me to create a new table for Measures so that I can create all the measures in this table ?" -
Some people do that.  Depends on how many measures you have.  Since measures are what you use when counting, summing (working with) numbers and dollars, etc., you can also keep them on the fact (transaction) table.

The formulas look fundamentally right to me, but you would have to test them out.  I am also fairly new to Power BI so there could be some tweaking needed.  Right now there are not a lot of experts out here on Power BI, but it is becoming a bigger deal.  Guessing you will begin to see the expertise grow quickly.  Let me know how things work out.

 
One more thing that could be helpful going forward:

Calculated Columns are best used to create data for slicing data.  For instance, using an If statement to categorize prices into "low, medium, or high".  Though some calculations can be made as Calculated Columns (quantity * price) it is better to use (in most cases) Measures to do that.  Measures do not take up space in the data model, Calculated Columns do.
Ok thanks Tom . Good to know tat .