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
warrencowan
Helper I
Helper I

Fill in blank values in time series data, based on last value.

Hi everyone

 

I am trying to create time series visuals (matrix and line charts primarly) from a snapshot table. Product have a position for the day, but different products in the table have different frequency schedules and days on which their position is recorded. I've pasted an example below. 

 

snapshot tablesnapshot table

I have linked this table to a seperate date table in the model, but if I try to put this data in a matrix it highlights the blank values on the dates where there is no data. In line graphs this will produce very peaky and troughy lines for the blank date too.

 

snapshot table in matrixsnapshot table in matrix

 

I want to create a formula that populates each blank date cell with the value of the position from the most recent snapshot, and ideally looks further back than the last series of the dates that are filtered into the visual. I've illustrated below. 

matrix populated with formula fieldmatrix populated with formula field

The black dates in the above table are the ones from the snapshot table where as the orange ones are the ones I am trying to create from looking back for the last data where a vlaue is recorded. The green numbers are doing the same but I have highlghted them another colour to highlight that they are looking further back than the dates in the current table.

 

I am presuming I will need to create an alternative measure using look back functions like lastdate, last/first nonblank, or something, and chart this measure instead. But after days of mistakes I am struggling.

 

Any help warmly appreciated.

 

 

Warren

1 ACCEPTED SOLUTION
ImkeF
Super User
Super User

Hi Warren,

you need to connect your snapshot table to a date table. Then you can use a measure like this:

 

Last Position= 
CALCULATE( MAX( SnapshotTable[Position] )
            ,LASTNONBLANK( DATESBETWEEN( 'Date'[Date],BLANK(),LASTDATE( 'Date'[Date] ) )
                           ,CALCULATE( COUNT( SnapshotTable[Position] ))
                          )
          )

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

5 REPLIES 5
warrencowan
Helper I
Helper I

Thankyou both for coming to my aid, and thanks Imke for your solution. You have solved one of my oldest gripes with our data storeage. Previously we would have copied values across each day resulting in huge storage over time, and long data returns in queries. Many many thanks for your help.

I think I've solved this (using query editor) but I'm not sure since your example data above is incomplete relative to the example of what you want for the finished product.  For example, in the finished matrix, for the first row (Product 1), how did you get all of those values based on the example you gave?  I assume that was based off of more complete data.

 

If this picture indicates that I have solved this, I will provide a link to the PBIX

 

Capture.PNG

I can confirm that @ImkeF's solution works, and is much simpler and more performant than mine.  I need to improve my DAX skills...

ImkeF
Super User
Super User

Hi Warren,

you need to connect your snapshot table to a date table. Then you can use a measure like this:

 

Last Position= 
CALCULATE( MAX( SnapshotTable[Position] )
            ,LASTNONBLANK( DATESBETWEEN( 'Date'[Date],BLANK(),LASTDATE( 'Date'[Date] ) )
                           ,CALCULATE( COUNT( SnapshotTable[Position] ))
                          )
          )

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Anonymous
Not applicable

Great DAX, thanks! Follow-up question for you: how do you calculate Number of Product by Position for every date?

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.