cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
BIstudent
New Member

Calculating The Number of Orders Per Day

Hi,

 I am using the Adventure Works 2020 Data Model. I have included a simplified example of the tables.

BIstudent_0-1638025035859.png

I would like to create a measure that would allow me to display the number of orders per day or other period specified in a chart.  I have been able to create a table using the following DAX code:

 

TestTable = SUMMARIZE(Sales, 'Date'[Date], "Number of Orders" ,DISTINCTCOUNT('Sales Order'[Sales Order]))

 

but I am having trouble getting to returing a single value required for a measure in a chart. 

 

Thanks in advance.

 

 

 

 

3 REPLIES 3
speedramps
Super User
Super User

The best solution is reshape the input data to 1 calendar dimension table and 1 fact sales table using PowerQuery.
Then the DAX is easy. Howvere ,if you want or need to do it the hard way .... 

 

Create 2 new measures

 

Sales indicator =
// This will return 1 if the selected period (year/month) has any sales records
// we use ISEMPTY with a NOT because it is more efficient than counting lots of records
// then use INT to transform true/false to an integer because boolean variables cant be used in the Filters pane
INT(NOT(ISEMPTY(Sales)))
 
Orders with sales =
// get a subset of records that are in your context (eg year/month) 
// then count the orders in the subset
VAR
mysubset = FILTER('Sales Order',[Sales indicator] = 1)
RETURN
CALCULATE(
DISTINCTCOUNT('Sales Order'[Sales Order]),
mysubset )
 
Create and check a report with ...
year, month and [Orders with sales]
aj1973
Community Champion
Community Champion

HI @BIstudent 

It looks like you have made a mistake in the name of the Table "Dates"

aj1973_0-1638028625932.png

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

negi007
Super User
Super User

@BIstudent  in this case, you could have created a simple measure like below and then it will accordingly will show the data as per time period selected (year, month, week, day etc.) in your visual

 

Orders_daily = distinctcount(sales_order)

 

let me know if i am missing something here. 




Did I answer your question? Mark my post as a solution!
Appreciate your Kudos


Proud to be a Super User!

Follow me here


Helpful resources

Announcements
May 23 2022 epsiode 5 without aka link.jpg

The Power BI Community Show

Welcome to the Power BI Community Show! Jeroen ter Heerdt talks about the importance of Data Modeling.

charticulator_carousel_with_text (1).png

Charticulator Design Challenge

Put your data visualization and design skills to the test! This exciting challenge is happening now through May 31st!

Power BI Dev Camp Session 22 with aka link 768x460.jpg

Check it out!

Mark your calendars and join us on Thursday, May 26 at 11a PDT for a great session with Ted Pattison!

Power BI Release May 2022 768x460.png

Check it out!

Click here to read more about the May 2022 updates!