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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
D3K
Advocate II
Advocate II

Calculated column with variable periods

Hey everyone!

Faced to the next problem, hope to get a help here.

Here is the question.

I have 2 tables:

- sales

- supplies

As you can see on the picture, product "111" arrives to the store with different intervals and always with different cost prices.

But it sells every day. 

So, how to make such calculated column in the table Sales, which would show the actual cost price of the particular product for the every period from and until the moments of the every cost price have been changed?

2020-01-30_14-40-50 (2).png

 

Any help will be highly appreciated. Thanks a lot!

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

create a new column in supplies


supply end Date = minx(filter(supplies,supplies[product id]=earlier(supplies[product id]) && supplies[Supply Date]> earlier(supplies[Supply Date])),supplies[Supply Date])

 

create a new column in sales

cost = minx(filter(sales,sales[sales_date]>=supplies[Supply Date]
&& (isbalnk(supplies[supply end Date]) || sales[sales_date] <supplies[supply end Date])),supplies[cost for 1 pc])

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

v-lid-msft
Community Support
Community Support

Hi @D3K ,

 

We can also create a  calculated column in Sales Table to meet you requeriement:

 

 

Cost Price for 1 pc =
VAR i = [Product ID]
VAR d = [Sales Date]
RETURN
    CALCULATE (
        SUM ( 'Supplies'[Cost price for 1 pc] ),
        FILTER (
            'Supplies',
            'Supplies'[Product ID] = i
                && 'Supplies'[Supply Date]
                    = CALCULATE (
                        MAX ( 'Supplies'[Supply Date] ),
                        FILTER (
                            'Supplies',
                            'Supplies'[Product ID] = i
                                && 'Supplies'[Supply Date] <= d
                        )
                    )
        )
    )

 


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
D3K
Advocate II
Advocate II

Thank you @v-lid-msft  and @amitchandak 

Both ways are working perfect!

v-lid-msft
Community Support
Community Support

Hi @D3K ,

 

We can also create a  calculated column in Sales Table to meet you requeriement:

 

 

Cost Price for 1 pc =
VAR i = [Product ID]
VAR d = [Sales Date]
RETURN
    CALCULATE (
        SUM ( 'Supplies'[Cost price for 1 pc] ),
        FILTER (
            'Supplies',
            'Supplies'[Product ID] = i
                && 'Supplies'[Supply Date]
                    = CALCULATE (
                        MAX ( 'Supplies'[Supply Date] ),
                        FILTER (
                            'Supplies',
                            'Supplies'[Product ID] = i
                                && 'Supplies'[Supply Date] <= d
                        )
                    )
        )
    )

 


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
amitchandak
Super User
Super User

create a new column in supplies


supply end Date = minx(filter(supplies,supplies[product id]=earlier(supplies[product id]) && supplies[Supply Date]> earlier(supplies[Supply Date])),supplies[Supply Date])

 

create a new column in sales

cost = minx(filter(sales,sales[sales_date]>=supplies[Supply Date]
&& (isbalnk(supplies[supply end Date]) || sales[sales_date] <supplies[supply end Date])),supplies[cost for 1 pc])

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.