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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
mddistributor1
Regular Visitor

Power Query - Data manipulation

I have data setup like the below table. Every time something is received the system creates a dash that is one higher than the prior one which shows everything that is yet to be received. I'm trying to calculate backorders by month, but I need the data setup differently. I could use some help on how this might be possible. 

VendorIDPoNumPODatePO AmountReceived amountReceived Date
11234/2/2022$1,000  
1123-14/2/2022$1,000$1004/8/2022
1123-24/2/2022$1,000$2005/25/2022
1123-34/2/2022$1,000$7006/3/2022
11255/6/2022$1,000  
1125-15/6/2022$1,000$7005/23/2022
1125-25/6/2022$1,000$2007/6/2022

 

I'd like to get to the table below. You'll notice on PO 125 that the same amount is in May and June because the backorder amount hasn't changed for June, but there is no received date for that month in the original data. 

VendorIDPoNumMonth EndBackorder Amount (PO Amount - Received)
1123-14/30/2022$900
1123-25/31/2022$700
1123-36/30/2022$0
1125-15/31/2022$300
1125-16/31/2022$300
1125-27/31/2022$100
6 REPLIES 6
CNENFRNL
Community Champion
Community Champion

Wierd to use PQ to solve such a question whereas DAX is designed to come into play in such a scenario. A DAX solution is way more concise and elegant.

CNENFRNL_0-1657201011678.png

 

For fun only, showcase of powerful worksheet formula,

CNENFRNL_1-1657202354526.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

This is an awesome setup. I wouldn't have come up with that. Do you have any way to get that extra date in there? Because June doesn't have anything showing for backorders even though there was $300 in backorders that month. This was originally why I was thinking power query because I wanted the actual data to have something for each date. If that is possible in DAX I'd love to know how to do it. 

A seemly rookie question but, in fact, fairly tricky.

CNENFRNL_1-1657313136383.png


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Now, here is the question. How do you aggregate this for all POs? Because I do want to be able to drill to that level, but most often I'd be looking at the vendor level or just overall backorder amount and tracking that. Again this is why my initial thought was Power Query. 

wdx223_Daniel
Super User
Super User

wdx223_Daniel_0-1657161575733.png

= #table({"VendorID","PoNum","Month End","Backorder Amount"},List.TransformMany(Table.Group(Source,{"VendorID","PoNum"},{"n",each Table.ToRows(Table.Sort(_,"Received Date"))},1,(x,y)=>let fx=(x)=>Text.Format("#[VendorID]-#[PoNum]",x&[PoNum=Text.BeforeDelimiter(Text.From(x[PoNum]),"-")]) in Value.Compare(fx(x),fx(y)))[n],each List.Accumulate(List.Skip(_),{{},_{0}{3}},(x,y)=>{x{0}&{List.FirstN(y,2)&{Date.EndOfMonth(Date.From(y{5})),x{1}-y{4}}},x{1}-y{4}}){0},(x,y)=>y))

 

This looks great, but I might need a little more explaination on this to completely understand what's going on. 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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