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
NSC7
Helper I
Helper I

Get last non 0 order qty for a week

Hi All,

 

I have a table with below data. I am trying to write DAX to get value for Qty PAB column.

Qty PAB column should show Order_Qty from the Max due_date of the week where we have non 0 value and if any week value is 0 for all Due dates Order_Qty should be picked from MAX(Due_Date) where Order_Qty > 0 and Due_Date <= Last Day of Week.

Ex-1

NSC7_0-1680039514805.png

Ex -2

NSC7_1-1680039909482.png

 

I tried below Dax but it is not working.

 

Qty PAB =

VAR _maxdate = CALCULATE(MAX(Query1[Due_date]),
FILTER(Query1,Query1[Order_Qty]>0 && Query1[Order_Type]= "PAB" && Query1[Due_date] <= SELECTEDVALUE(Query1[Last Day of Week] )))
RETURN CALCULATE(MAX(Query1[Order_Qty]),Query1[Due_date]=_maxdate)

 

Thanks

5 REPLIES 5
Greg_Deckler
Super User
Super User

@NSC7 Try:

Qty PAB Measure =
  VAR __MaxNZDate = MAXX(FILTER(ALL('Query1'),[Order_Qty] > 0), [Due Date])
  VAR __Result = MAXX(FILTER(ALL('Query1'), [Order_Qty] > 0 && [Due Date] = __MaxNZDate),[Order_Qty])
RETURN
  __Result

@ 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 for replying but It didn't work. I think i didn't mention the requirement clearly. 

Data I am showing is just sample data, there are multiple months and Weeks and multiple values for Display Column. Please check below screenshot. Please let me know if you have more questions.

 

NSC7_1-1680094422201.png

 

 

@NSC7 Can you post the sample data as text?


@ 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 , Please let me know if you need more details.

@Greg_Deckler , Please find below

 

ItemMonth OfWeek OfFirst Day of WeekDue_dateLast Day of WeekDisplayOrder_Qty
123-MarPrevious Week03/20/2303/20/2303/26/23PAB0
123-MarPrevious Week03/20/2303/22/2303/26/23PAB100
123-MarPrevious Week03/20/2303/23/2303/26/23PAB105
123-MarPrevious Week03/20/2303/24/2303/26/23PAB0
123-Mar3/27/202303/27/2303/27/2304/02/23PAB0
123-Mar3/27/202303/27/2303/28/2304/02/23PAB0
123-Mar3/27/202303/27/2303/29/2304/02/23PAB0
123-Mar3/27/202303/27/2303/30/2304/02/23PAB0
123-Mar3/27/202303/27/2303/31/2304/02/23PAB0
123-Mar3/27/202303/27/2304/01/2304/02/23PAB0
123-Mar3/27/202303/27/2304/02/2304/02/23PAB0
123-MarPrevious Week03/20/2303/20/2303/26/23PAB$0
123-MarPrevious Week03/20/2303/22/2303/26/23PAB$150
123-MarPrevious Week03/20/2303/23/2303/26/23PAB$200
123-MarPrevious Week03/20/2303/24/2303/26/23PAB$0
123-Mar3/27/202303/27/2303/27/2304/02/23PAB$0
123-Mar3/27/202303/27/2303/28/2304/02/23PAB$0
123-Mar3/27/202303/27/2303/29/2304/02/23PAB$0
123-Mar3/27/202303/27/2303/30/2304/02/23PAB$0
123-Mar3/27/202303/27/2303/31/2304/02/23PAB$0
123-Mar3/27/202303/27/2304/01/2304/02/23PAB$0
123-Mar3/27/202303/27/2304/02/2304/02/23PAB$0
123-MarPrevious Week03/20/2303/20/2303/26/23POH250
123-MarPrevious Week03/20/2303/22/2303/26/23POH0
123-MarPrevious Week03/20/2303/23/2303/26/23POH0
123-MarPrevious Week03/20/2303/24/2303/26/23POH0
123-Mar3/27/202303/27/2303/27/2304/02/23POH0
123-Mar3/27/202303/27/2303/28/2304/02/23POH0
123-Mar3/27/202303/27/2303/29/2304/02/23POH0
123-Mar3/27/202303/27/2303/30/2304/02/23POH0
123-Mar3/27/202303/27/2303/31/2304/02/23POH0
123-Mar3/27/202303/27/2304/01/2304/02/23POH0
123-Mar3/27/202303/27/2304/02/2304/02/23POH0

 

Expected output-

  23-Mar
ItemDisplayPrevious Week3/27/2023
1PAB105105
1PAB$200200
1POH250250

 

Thanks

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