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
Anonymous
Not applicable

Calculate daily change several products

Hi everyone,

 

I am very new to Power BI and I am struggling with a problem I can't figure out how to make it work. There are similar problems on this forum, but they often differ in a subtle way, so I can't figure out how to implement the solutions to my specific case.

 

So my data contains 3 columns:

Product           Date                     Amount in kg
Wheat01/01/221000
Corn01/01/22800
Beans01/01/221100
Wheat02/01/221100
Corn02/01/22950
Beans02/01/221300
Wheat03/01/221250
Corn03/01/221200
Beans03/01/221500

 

Now I want to add one column that shows the inventory of the product from the previous day ('Amount in kg previous day').

 

What is the best way to approach this problem?

Thank you!

 

 

 

2 ACCEPTED SOLUTIONS
tamerj1
Super User
Super User

Hi @Anonymous 
You can try 

Previous Day Amount =
VAR CurrentDate = Inventory[Date]
VAR T1 =
    CALCULATETABLE ( Inventory, ALLEXCEPT ( Inventory, Inventory[Product] ) )
VAR T2 =
    FILTER ( T1, Inventory[Date] < CurrentDate )
VAR PreviuosDate =
    MAXX ( T2, Inventory[Date] )
VAR T3 =
    FILTER ( T2, Inventory[Date] = PreviuosDate )
RETURN
    SELECTCOLUMNS ( T3, "Previous Day Amount", Inventory[Amount in kg] )

View solution in original post

PiEye
Resolver II
Resolver II

Hi E_E

You can use this method to return the previous value for a set value:

 

Prev =
CALCULATE(
[AmountinKG],
TOPN(
1,
FILTER(
ALLSELECTED( 'Table Name' ),
'Table Name'[Sales Date] < MAX('Table Name'[Sales Date] )
),
'Table Name'[Sales Date],
DESC
)
)
 
Does this work for you?
 
Pi

View solution in original post

4 REPLIES 4
PiEye
Resolver II
Resolver II

Hi E_E

You can use this method to return the previous value for a set value:

 

Prev =
CALCULATE(
[AmountinKG],
TOPN(
1,
FILTER(
ALLSELECTED( 'Table Name' ),
'Table Name'[Sales Date] < MAX('Table Name'[Sales Date] )
),
'Table Name'[Sales Date],
DESC
)
)
 
Does this work for you?
 
Pi
Anonymous
Not applicable

Thank you, will also play around with this one!

tamerj1
Super User
Super User

Hi @Anonymous 
You can try 

Previous Day Amount =
VAR CurrentDate = Inventory[Date]
VAR T1 =
    CALCULATETABLE ( Inventory, ALLEXCEPT ( Inventory, Inventory[Product] ) )
VAR T2 =
    FILTER ( T1, Inventory[Date] < CurrentDate )
VAR PreviuosDate =
    MAXX ( T2, Inventory[Date] )
VAR T3 =
    FILTER ( T2, Inventory[Date] = PreviuosDate )
RETURN
    SELECTCOLUMNS ( T3, "Previous Day Amount", Inventory[Amount in kg] )
Anonymous
Not applicable

That seems to solve it, thank you very much.

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.