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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Revolution
Frequent Visitor

Fetch last non-blank value for any date with multiple filters

I am trying to produce the sum of a running total for all SKU's selected by slicers on any selected date.

 

I have a table with transaction data as follows:

Warehouse  |SKU |TxDate |DayQty |RT (Running Total)

 

This measure works for each SKU individually:

 

 

 

RT by Size = 
VAR d = 
    SELECTEDVALUE('Date'[Date])
RETURN
    CALCULATE(
        LASTNONBLANKVALUE(StkDayQty[TxDate], SUM(StkDayQty[RT])),
        StkDayQty[TxDate] <= d,
        CROSSFILTER('Date'[Date], StkDayQty[TxDate], none)
    )

 

 

 

I created a table that assigns a unique ID (IdWhseStk) for each SKU in each warehouse and attempted to create a measure that will sum RT for all selected by slicers:

 

 

 

RT Total = SUMX(
    VALUES(WhseStk[IdWhseStk]),
    [RT by Size])

 

 

 

This does not work: 

Revolution_0-1717801146495.png

Also tried this with the same result:

 

 

 

RT Selected = 
VAR _RTSize = [RT by Size]

RETURN
if( isfiltered(WhseStk[IdWhseStk]) ,
SUMX (
VALUES ( WhseStk[IdWhseStk] ),_RTSize))

 

 

 

I even tried to merge the entire date table to each SKU before calculating the RT in Power Query so that I have a distinct RT for every SKU on every date but it results in millions of rows.

 

I can't find a solution that I can apply to my dataset. Any advice would be much appreciated.

 

1 ACCEPTED SOLUTION

This doesn't work because I have the same SKU for different warehouses. Hence the helper table which was created in SQL at the source. I discovered duplicates so made a new table containing unique IDs for each SKU+Warehouse. I now have it working. 

View solution in original post

4 REPLIES 4
MarkLaf
Super User
Super User

Not sure you need a helper table. I assume your main issue is that your date slicer is filtering the VALUES ( WhseStk[IdWhseStk] ) that you are iterating over. Try:

RT Total = 
SUMX(
    CALCULATETABLE( VALUES(StkDayQty[SKU]), REMOVEFILTERS( 'Date' ) ),
    [RT by Size]
)

 

This doesn't work because I have the same SKU for different warehouses. Hence the helper table which was created in SQL at the source. I discovered duplicates so made a new table containing unique IDs for each SKU+Warehouse. I now have it working. 

scee07
Resolver I
Resolver I

From what I understand of the above, this might be a visual calculation case. I took the canonical Contoso sales data and calcualuated the profit as calculated column in the visual (Just to show that a calculated column in the visual works)

 

scee07_0-1718027129353.png

In my data there is a product key and date key that play the roles of your field. 

Then you can use the running sum as another calculated column in the visual: 

RunningSum = RUNNINGSUM([Profit])
scee07_1-1718027331439.png

Then I selected a few date keys with a slicer and did another date slicer with "before date" settings

You can see that this produces indeed the running totals acrosss the product keys

scee07_2-1718027435117.png

Hope this helps.

The approach definetely reduces filter context complexity. It is a matter of taste. 

 

Best regards 

 

Christian

 

Dangar332
Super User
Super User

Hi, @Revolution 

It's better if you provide Some sample data

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.