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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

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
Community Champion
Community Champion

@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


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



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 , 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
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

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.