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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
JimsonBonilla
Frequent Visitor

Rolling Totals to date with last available aggregate for days/weeks/months with no values

Hi, community!

 

I have an apparently very easy problem to solve, but I just don't seem to get it  right no matter what I do.

Getting into the problem, I have various products (let's call them SKUs) grouped by batches (called IO). I want to see the evolution of the inventory value of said SKUs, but, and here comes the real cause of complexity, the variations generally don't occur on the same dates, but I need to know what is the last value of my inventory for each day, even when they inventory value is the same as the day before.

 

For example, I have this referential facts table with the movements in my inventory

 

 

DateMain IOIOProductPlotBatch DescriptionUSD (Thousands)Motive
01/01/202218881888-L-1SKU-11SKU-1.1.2210IO opening
07/01/202219991999-L-2SKU-22SKU-2.2.2225IO opening
15/02/202218881888-L-1SKU-11SKU-1.1.22-0.5Exchange Rate Adjustement
13/08/202219991999-L-2SKU-22SKU-2.2.220.84Exchange Rate Adjustement
21/10/202219991999-L-2SKU-22SKU-2.2.22-0.34Defective Products
21/12/202218881888-L-1SKU-11SKU-1.1.22-0.75Defective Products
07/01/202319991999-L-2SKU-22SKU-2.2.22-0.75Environment Damage
07/03/202318881888-L-1SKU-11SKU-1.1.22-0.38Environment Damage
18/11/202318881888-L-1SKU-11SKU-1.1.22-0.37Pre-Holidays Adjustment
18/11/202319991999-L-2SKU-22SKU-2.2.22-1.3Pre-Holidays Adjustment
08/01/202419991999-L-2SKU-22SKU-2.2.22-23.45Holidays Liquidation

 

My goal is to create a visual and a matrix that show me the evolution of the inventory value through time for each product, but when I try to create my visuals, the results are not what I expected.

For the line chart and table, my goal is this:

JimsonBonilla_3-1706714837349.png

 

JimsonBonilla_1-1706716208093.png

 

 

But when I create my measure, it returns me this instead:

JimsonBonilla_6-1706715100531.png

 

JimsonBonilla_0-1706716188695.png

 

My measure is this (I've tried a lot of other, more complex, measures found on the internet, but the results are basically the same) :

 

 

 

 

agg_measure = 
VAR _max = MAX(Table1[Date])
VAR _calc = CALCULATE(
                    SUMX(Table1,
                               Table1[USD (Thousands)]),
                               ALL('Calendar'),
                               Table1[Date]<=_max
                         )
//return IF(_calc<>0,_calc,BLANK())
return _calc

 

 

 

 

 

Ideally, I would prefer for the graph not to show 0 values (when the batch is sold out), but the line to simply stop appearing.

 

And I would also love for the report to automatically show me the inventory value up to the present day, I suspect I only need to replace the VAR _max for a VAR _today=TODAY(), but I have no way to try it and evaluate the result.

 

So, that's it. I don't know if I can or have to share the referential .xlsx, but if you need it, I'm more than happy to share it if it helps you help me. Thank you for your time.

1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @JimsonBonilla ,

 

I suggest you to create an unrelated DimDate table to help calcualtion.

 

DimDate = VALUES('Table'[Date])

 

Measure:

 

SKU-1 = CALCULATE(SUM('Table'[USD (Thousands)]),FILTER('Table','Table'[Product] = "SKU-1" && 'Table'[Date]<= MAX(DimDate[Date])))
SKU-2 = CALCULATE(SUM('Table'[USD (Thousands)]),FILTER('Table','Table'[Product] = "SKU-2" && 'Table'[Date]<= MAX(DimDate[Date])))

Result is as below.

vrzhoumsft_0-1706765542892.png

 

Best Regards,
Rico Zhou

 

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

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @JimsonBonilla ,

 

I suggest you to create an unrelated DimDate table to help calcualtion.

 

DimDate = VALUES('Table'[Date])

 

Measure:

 

SKU-1 = CALCULATE(SUM('Table'[USD (Thousands)]),FILTER('Table','Table'[Product] = "SKU-1" && 'Table'[Date]<= MAX(DimDate[Date])))
SKU-2 = CALCULATE(SUM('Table'[USD (Thousands)]),FILTER('Table','Table'[Product] = "SKU-2" && 'Table'[Date]<= MAX(DimDate[Date])))

Result is as below.

vrzhoumsft_0-1706765542892.png

 

Best Regards,
Rico Zhou

 

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

@JimsonBonilla , Based on what I got.
Make sure date from date table is used in visual, Try like

agg_measure =
VAR _max = MAX(Table1[Date])
VAR _calc = CALCULATE(
SUMX(Table1,
Table1[USD (Thousands)]),
filter(ALL('Calendar'),'Calendar'[Date] <= max('Calendar'[Date])
'Calendar'[Date]<=_max
))
//return IF(_calc<>0,_calc,BLANK())
return _calc

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.