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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
wlknsn
Helper I
Helper I

Fill empty rows/values with previous/last measure or calculated value

Hi,

 

I'm trying to find a DAX solution for a measure or calculated column which basically returns the last measure/calculated value if the cell is empty. This result should not be an aggregation, simply the last value. The point is that the values could be either measures or calculated columns which can then be used for other calculations.

 

Check below for example in terms of stock keeping.

 

 FillValues.png

 

PS: the totals are wrong in the last two tables. Please ignore.

 

Sample data:

 

WarehouseProductTimeStampMeasure
XA18/08/2018  09:00:004
XA18/08/2018  11:00:005
XA18/08/2018  14:00:009
XA18/08/2018  16:00:007
XB18/08/2018  08:00:002
XB18/08/2018  13:00:005
XB18/08/2018  15:00:006
XB18/08/2018  16:00:002
YA18/08/2018  07:00:008
YA18/08/2018  11:00:008
YA18/08/2018  14:00:004
YB18/08/2018  07:00:009
YB18/08/2018  08:00:002
YB18/08/2018  13:00:001
YB18/08/2018  15:00:009
YB18/08/2018  17:00:006

 

Many thanks!

4 REPLIES 4
yosytrejo001
Regular Visitor

Hi friends, 
I'm looking for a solution  to my problem, i'm trying to obtain the previous value for each date. It should be a calculated column because i'll use it in DISTINCTCOUNTNOBLANK() function and it requires a column.

I'm a Spanish speaker, my apologizes.
 Traducción: Busco una manera de obtener el valor anterior para cada una de las fechas que se encuentran en mi tabla calendario. Necesito una columna calculada ya que lo usaré en la función DISTINCTCOUNTNOBLANK(). 


Tabla - Stock Histórico - All movements of stock by product, warehouse and date. Here we have the stock only if an in or out of stock happened in that date.

yosytrejo001_0-1624298910187.png

Tabla - Calendario : All dates in my calendar
yosytrejo001_1-1624298967401.png

Resultado Deseado: I want to obtain a the stock in all dates in my calendar, if it's in blank it should be filled by the previous value.

yosytrejo001_2-1624299371099.png


De antemano agradezco el apoyo y adjunto el archivo Test. https://mistrperu-my.sharepoint.com/:u:/g/personal/yosy_trejo_mistr_com_pe/EZk1yjmAcqdFv14U5gNGeoEBy... 

Seward12533
Solution Sage
Solution Sage

While its possible in DAX - seethis solution https://community.powerbi.com/t5/Desktop/Fill-down-collumn-information-based-on-condition/td-p/43946...

 

If all your values are numeric then you can use the Fill Option in the Query Editor that will replace blanks with the values in previous rows within columns.

 

snip_20180818223836.pngsnip_20180818224040.pngsnip_20180818224103.png

 

 

As mentionned before, I need to fill this based on a measure. The power query solution is based on data, and not a measure/calculation. Same for the dax solution, that will not work with measure. It's the last measure that needs to be filled.

Yggdrasill
Responsive Resident
Responsive Resident

I've used this as a calculated column

 

Fill empty rows = 
VAR LastNonBlankDate =
    CALCULATE (
        LASTNONBLANK ( dimDates[Date]; 1 );
        FILTER (
            ALL ( dimDates );
            dimDates[Date]<= EARLIER (  dimDates[Date] )
                && NOT ( ISBLANK ( dimDates[YourColumnWithBlankRows]) )
        )
    )
RETURN
    CALCULATE (
        SUM ( dimDates[YourColumnWithBlankRows] );
        FILTER ( ALL ( dimDates ); dimDates[Date] = LastNonBlankDate )
    )

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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