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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
joshua1990
Post Prodigy
Post Prodigy

Count number New and Lost Orders

Hello everyone!

I would like to calculate the number of new and lost orders per week based on a daily archive.

The daily archive has this structure:

Order NumberDate ArchiveArticle
10001.07.2021A
10101.07.2021B
10201.07.2021C
10301.07.2021D
10401.07.2021E
10501.07.2021F
10601.07.2021G
10701.07.2021H
10801.07.2021I
10901.07.2021J
10002.07.2021A
10102.07.2021B
10202.07.2021C
10302.07.2021D
10402.07.2021E
10502.07.2021F
10602.07.2021G
10702.07.2021H
10802.07.2021I

 

This is the structure if I pivot these numbers:

 

 WK26WK27
 DoFrSaSoMoDiMiDoFr
Order ID01.07.202102.07.202103.07.202104.07.202105.07.202106.07.202107.07.202108.07.202109.07.2021
1001111     
101111111111
102111111111
103111111111
104111111111
105111111111
106111111111
107111111111
108111111111
109111111111
110        1
Total10101010999910

 

As you can see, there is a new order in the last column/ date as well as a order lost on the 05.07.2021.

In the end I would like to get a matrix in this format:

WK# Orders# New Orders# Lost Orders
261001
271010

 

 

How would you do that using DAX?

I have added a sample file here:

https://easyupload.io/901pnv

 

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@joshua1990 Hmm, well, first of all I would not pivot your data. You can find new orders using DISTINCT and EXCEPT. Lost orders would essentially be the same. You would want to have a calculated column in your original table format that defined week number (WEEKNUMBER). If you have that, then maybe something like the following:

New Orders = 
  VAR __CurrentWeek = MAX('Table'[WeekNumber])
  VAR __LastWeek = __CurrentWeek - 1
  VAR __CurrentOrders = DISTINCT(SELECTCOLUMNS(FILTER('Table',[WeekNumber] = __CurrentWeek),"__Order",[Order]))
  VAR __LastWeekOrders = DISTINCT(SELECTCOLUMNS(FILTER('Table',[WeekNumber] = __LastWeek),"__Order",[Order]))
RETURN
  COUNTROWS(EXCEPT(__CurrentOrders,__LastWeekOrders))
  


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler : Thanks, but using your approach just shows me how many distinct orders we have per week.

joshua1990_0-1627450704978.png

I would assume we need to take the first and last date per order into consideration to reflect new and lost orders, right?

 

@joshua1990 Apologies, you will need some ALL statements in there:

New Orders = 
  VAR __CurrentWeek = MAX('Table'[WeekNumber])
  VAR __LastWeek = __CurrentWeek - 1
  VAR __CurrentOrders = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'),[WeekNumber] = __CurrentWeek),"__Order",[Order]))
  VAR __LastWeekOrders = DISTINCT(SELECTCOLUMNS(FILTER(ALL('Table'),[WeekNumber] = __LastWeek),"__Order",[Order]))
RETURN
  COUNTROWS(EXCEPT(__CurrentOrders,__LastWeekOrders))


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

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

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.