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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
noncek
Frequent Visitor

Performing operations on a table based on dates in rows in other table

Hello!

 

I am currently migrating an Excel-based solution into Power BI and have encountered a pickle I struggle to move past.

 

I have a table with order quotations for some products. Each product has some components, however their number differs from product to product (it can be between 1 and as many as 30 components per product). Also, each product has many different quotations, based on date and they can be on any date (this is not a case of a new batch of quotations for all products being updated e.g. every 1st January).

 

This table looks a bit like that (and has 200k+ rows altogether):

ProcuctQuote DateComponentComp. Cost
P12018-01-01C110
P12018-01-01C215
P12018-01-01C310
P12019-01-01C111
P12019-01-01C213
P12019-01-01C310
P22018-03-01C42
P22018-03-01C59
P22020-01-01C43
P22020-01-01C510
P32020-01-01C6100
P32020-01-15C6103
P42016-05-30C18
P42016-05-30C212
P42016-05-30C74
P42019-01-01C111
P42019-01-01C213
P42019-01-01C75
P52001-01-01C810

 

So e.g. starting from 2018-01-01, the cost for P1 is 35 (10+15+10), and then from 2019-01-01 until now it is 34 (11+13+10).

For P2 the cost is 11 (2+9) between 2018-03-01 and 2020-01-01 and then rises to 13 (3+10). There was no quotation for P2 in 2019.

For P5 there is just one general quotation from 2001 and it doesn't change at all.

 

I also have table with volumes for each product looking like that:

ProcuctMonthQuantity
P12018-01-01100
P12018-02-01120
P12018-03-01150
  
P12020-05-01140
P22018-01-0135
P22018-02-0140
P22018-03-0130
  
P22020-05-0150
  

 

What I need to do is to get the spend on each product per month (and obviously have this analyzed further by years, suppliers, categories, etc.). I also need to see the spend on components themselves (as they can appear in more than one product).

 

I think I need to create some kind of function comparing quotation dates in one table to volume dates in the other, but struggle to even start on this 😕

 

Any hints, pointers and help greatly appreciated.

7 REPLIES 7
MFelix
Super User
Super User

Hi @noncek ,

 

What you need to create is a star schema model (https://docs.microsoft.com/en-us/power-bi/guidance/star-schema) so accordingly to you setup you need to have a calendar table and a products table.

 

Check link to create calendar table  (there are other based on power query also). Then you can make your calculations based on dates and also on products.

 

In attach PBIX file is a very simple presentation needs to be structure so the calculations give you the totals between periods, but please just check if the values for the specif dates are correct if yes I can seup the measures for the dates between periods.

 

Please tell me if this can help.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



noncek
Frequent Visitor

Hi @MFelix ,

 

thanks for your reply and help!

I did have calendar table and data schema already in my model, however I see it wasn't connected properly. I went with your proposal.

 

As for the pbix attached, it does show expected values for the periods when there are any quotations. If you could help with filling the gaps for periods between quotations, I'd be very grateful.

I can't figure out though, where do totals come from in this one?

c2.PNG

 

 

 

Whereas total for specific year make sense, the totals for rows and columns boggle my mind...

 

Anyway, thanks again for your help!

Hi @noncek ,

 

Just a few question that appear on the calculation I was making and can change the way we need to approach the problem:

 

  • On product P3 you have Quotations you have the same component with two different dates is this correct?
  • Can you have several quotations for different components on different dates within the same month if so what is the date that is consider?

Just to clarify and get the correct calculations.

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



noncek
Frequent Visitor

Hi @MFelix 

 

For both your questions the answer is positive.

There can be cases, where a product has more than one quotation during a month. There can alos be a situation when in a cerain month there is a new quotation (or a couple of quotations) for only one of the components for the product, while the others don't have any new quotation (hence no change).

 

Generally the logic should be that to calculate the cost of the product (=sum of costs if its components) at any point in time, we should take the latest available quotation for each component.

So in the example product P3 costs 100 between 2020-01-01 and 2020-01-14 and from 2020-01-15 the cost changes to 103 (until new quotation appears for the component C6 - in this particular case it has only one component).

The volumes file is granular down just to months, so the model assumes volumes are coming always on the first day of the month. I didn't put the volumes for P3 in my example, but assuming they were 1000 pcs every month, the spend on P3 in Jan 2020 would be 100.000, Feb 2020 would be 103.000 and all following months at 103.000.

 

Hope this answers your question.

And once again thank you for your help and staying on the case!

Hi @noncek ,

 

I'm sorry I didnt get back to you yet, however I am doing some trainig and is hard to get the time.

 

I will put you in touch with a great datanaut.

 

@parry2k  can you please fill on my behalf on this question? I have made a smal file but feel free to get a different and better solution.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Thanks @MFelix  I can surely assist with this.

 

@noncek It will be much easier if you put sample data in excel file and share it here and also one sheet put the expected result, it will help me to create the solution in Power BI and send it back to you otherwise there will be lot of back and forth.

 

Cheers

P



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thanks @MFelix  for referral and thanks @parry2k for taking interest!

 

As a regular community member I don't seem to have an option to attach a file directly here, but please find a transfer link to the xls:

https://wetransfer.com/downloads/515315cc8889932359751c914a68084020200625113807/bcf2da8976af55f1aa91...

 

Have a great day!

K

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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