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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Super User
Super User

@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))
  

@ 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!:
The Definitive Guide to Power Query (M)

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))

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors