Forum Discussion

babyjb1979's avatar
babyjb1979
Icon for Helper I rankHelper I
2 years ago
Solved

Fill up gaps with duplicate date

Hi Power Bi Gurus,

 

I have a table with date and value, I am using the DAX code to fill up the gaps as following:

New Value =
VAR LastNonBlankDate =
    CALCULATE (
        FIRSTNONBLANK ( TableName[Date], 1 ),
        FILTER (
            ALL ( TableName ),
            TableName[Date] >= EARLIER ( TableName[Date] )
            &&TableName[ID] = EARLIER ( TableName[ID] )
                && FIRSTNONBLANK( TableName[Value],1 ) )   )
   RETURN
    CALCULATE (
        MIN( TableName[Value] ),
        FILTER ( ALL ( TableName ), TableName[Date] = LastNonBlankDate )  )

It is perfectly solution. But if there are duplicated date, and value(01/02/2023 which is duplicated) something wrong happened. I have to keep the duplicated rows. 

So I want to introduce a var to summarize the date and value, then I stuck here :

New Value 2 =
VAR tb=SUMMARIZE('TableName',TableName[ID],TableName[Date],TableName[Value])
VAR LastNonBlankDate=

    CALCULATE (
        FIRSTNONBLANK ( [Date], 1 ),
        FILTER (
            ALL ( tb ),
            [Date] >= EARLIER ( [Date] )
            &&[ID] = EARLIER ( [ID] )
                && not( ISBLANK([Value]) )
        ))
   
RETURN
    CALCULATE (
        SUM( [Value] ),
        FILTER ( ALL ( tb ), [Date] = LastNonBlankDate )
    )

Please help me out!!!

 

Thank you in advance!

Branko

 

IDDateValue
A1/1/2023 
A1/2/20236
A1/2/20236
A1/4/2023 
A1/5/202312
A1/6/2023 
B1/3/2023 
B1/6/2023 
B1/7/2023 
B1/8/2023 
B1/9/20238
B1/10/2023 
B1/15/2023 
B1/17/202343
B1/18/2023 
C1/19/2023 
C1/20/2023 
C1/21/202311
C1/22/2023 

 

 

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi  babyjb1979 ,

     

    Here are the steps you can follow:

    1. Create measure.

    Measure =
    IF(
        MAX('Table'[Value]) =BLANK(),
        MINX(
            FILTER(ALL('Table'),
            'Table'[ID]=MAX('Table'[ID])&&'Table'[Date]>MAX('Table'[Date])&&'Table'[Value]<>BLANK()),[Value]),
            MAX('Table'[Value]))
    
    

    2. Result:

     

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

5 Replies

  • Would you like to address gaps in your data by inserting missing dates and updating the value column with the most recent non-blank value? For instance, if there's a missing date like 1/3/2023, would you want to create a new row with that date and a value of 6 copied from the previous date?

    • babyjb1979's avatar
      babyjb1979
      Icon for Helper I rankHelper I

      I want to fill up the blank with the lastest non-blank value

       

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi  babyjb1979 ,

     

    Here are the steps you can follow:

    1. Create measure.

    Measure =
    IF(
        MAX('Table'[Value]) =BLANK(),
        MINX(
            FILTER(ALL('Table'),
            'Table'[ID]=MAX('Table'[ID])&&'Table'[Date]>MAX('Table'[Date])&&'Table'[Value]<>BLANK()),[Value]),
            MAX('Table'[Value]))
    
    

    2. Result:

     

     

    Best Regards,

    Liu Yang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

    • babyjb1979's avatar
      babyjb1979
      Icon for Helper I rankHelper I

      Anonymous 
      The logic appears to be correct, but please check that the data is still incorrect. Please use the new data to test. Thank you very much for your time and help!!!

       

       

        
         
      IDDateValue
      10232019/1/2023 0:00 
      10232019/2/2023 0:00 
      10232019/3/2023 0:00 
      10232019/4/2023 0:00 
      10232019/5/2023 0:00 
      10232019/6/2023 0:00 
      10232019/7/2023 0:00 
      10232019/8/2023 0:00 
      10232019/9/2023 0:00 
      10232019/10/2023 0:00 
      10232019/11/2023 0:00 
      10232019/12/2023 0:0012
      10232019/26/2023 0:00 
      10232019/27/2023 0:00 
      10232019/28/2023 0:00 
      10232019/29/2023 0:00 
      10232019/30/2023 0:00 
      102320110/1/2023 0:00 
      102320110/2/2023 0:007
      2219349/1/2023 0:00 
      2219349/2/2023 0:00 
      2219349/3/2023 0:00 
      2219349/4/2023 0:00 
      2219349/5/2023 0:005
      2219349/11/2023 0:00 
      2219349/12/2023 0:00 
      2219349/13/2023 0:00 
      2219349/14/2023 0:00 
      2219349/15/2023 0:00 
      2219349/16/2023 0:00 
      2219349/17/2023 0:00 
      2219349/18/2023 0:00 
      2219349/19/2023 0:00 
      2219349/20/2023 0:00 
      2219349/21/2023 0:00 
      2219349/22/2023 0:00 
      2219349/23/2023 0:00 
      2219349/24/2023 0:00 
      2219349/25/2023 0:00 
      2219349/26/2023 0:0016
      2460759/1/2023 0:00 
      2460759/2/2023 0:00 
      2460759/3/2023 0:00 
      2460759/4/2023 0:00 
      2460759/5/2023 0:00 
      2460759/6/2023 0:00 
      2460759/7/2023 0:00 
      2460759/8/2023 0:00 
      2460759/9/2023 0:00 
      2460759/10/2023 0:00 
      2460759/11/2023 0:00 
      2460759/12/2023 0:00 
      2460759/13/2023 0:00 
      2460759/14/2023 0:0014
      2460759/27/2023 0:00 
      2460759/28/2023 0:00 
      2460759/29/2023 0:00 
      2460759/30/2023 0:00 
      24607510/1/2023 0:00 
      24607510/2/2023 0:00 
      24607510/3/2023 0:007

       

  • Anonymous 
    Hi Liu,

    The logic appears to be correct, but please check that the data is still incorrect. Please use new data to test

    IDDateValue
    10232019/1/2023 
    10232019/2/2023 
    10232019/3/2023 
    10232019/4/2023 
    10232019/5/2023 
    10232019/6/2023 
    10232019/7/2023 
    10232019/8/2023 
    10232019/9/2023 
    10232019/10/2023 
    10232019/11/2023 
    10232019/12/202312
    10232019/26/2023 
    10232019/27/2023 
    10232019/28/2023 
    10232019/29/2023 
    10232019/30/2023 
    102320110/1/2023 
    102320110/2/20237
    2219349/1/2023 
    2219349/2/2023 
    2219349/3/2023 
    2219349/4/2023 
    2219349/5/20235
    2219349/11/2023 
    2219349/12/2023 
    2219349/13/2023 
    2219349/14/2023 
    2219349/15/2023 
    2219349/16/2023 
    2219349/17/2023 
    2219349/18/2023 
    2219349/19/2023 
    2219349/20/2023 
    2219349/21/2023 
    2219349/22/2023 
    2219349/23/2023 
    2219349/24/2023 
    2219349/25/2023 
    2219349/26/202316
    2460759/1/2023 
    2460759/2/2023 
    2460759/3/2023 
    2460759/4/2023 
    2460759/5/2023 
    2460759/6/2023 
    2460759/7/2023 
    2460759/8/2023 
    2460759/9/2023 
    2460759/10/2023 
    2460759/11/2023 
    2460759/12/2023 
    2460759/13/2023 
    2460759/14/202314
    2460759/27/2023 
    2460759/28/2023 
    2460759/29/2023 
    2460759/30/2023 
    24607510/1/2023 
    24607510/2/2023 
    24607510/3/20237