SOLVED

PQ / Data Model - Turning non consecutive days into consecutive with the value from previous day

%3CLINGO-SUB%20id%3D%22lingo-sub-1935294%22%20slang%3D%22en-US%22%3EPQ%20%2F%20Data%20Model%20-%20Turning%20non%20consecutive%20days%20into%20consecutive%20with%20the%20value%20from%20previous%20day%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1935294%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3EI%20have%20a%20very%20particular%20use%20case%2C%20where%20I%20have%20a%20data%20set%20with%20account%20balances%20and%20a%20data%20set%20with%20all%20calendar%20dates%20for%20a%20period.%20The%20account%20balances%20however%20may%20only%20contain%20some%20of%20the%20dates.%20I%20want%20to%20use%20return%20a%20Table%20or%20a%20Pivot%20Table%20with%20Balances%20for%20all%20calendar%20dates%20where%20the%20blanks%20are%20is%20the%20exact%20balance%20of%20the%20previous%20balance%20known.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHave%20tried%20to%20visualize%20a%20simple%20use%20case%20below%2C%20where%20I%20would%20like%20as%20an%20example%20Konto%201%20to%20return%20400%20for%20both%2004.01.2020%20and%2005.01.2020%2C%20etc.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHave%20tried%20to%20solve%20this%20using%20DAX%20but%20no%20luck.%20Will%20do%20this%20on%20relatively%20large%20datasets%20(100%20accounts%20*%20365%20days)%20and%20not%20really%20to%20concerned%20whether%20it%20is%20solved%20in%20the%20Query%20or%20in%20DAX%20etc.%20as%20long%20as%20it%20handles%20the%20amount%20of%20data.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22%22%3EAny%20suggestions%20would%20be%20much%20appreciated.%3C%2FP%3E%3CP%20class%3D%22%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Image.JPG%22%20style%3D%22width%3A%20819px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F236319i753547E7C9D9B837%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22Image.JPG%22%20alt%3D%22Image.JPG%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1935294%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EBI%20%26amp%3B%20Data%20Analysis%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1935365%22%20slang%3D%22en-US%22%3ERe%3A%20PQ%20%2F%20Data%20Model%20-%20Turning%20non%20consecutive%20days%20into%20consecutive%20with%20the%20value%20from%20previous%20da%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1935365%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F883239%22%20target%3D%22_blank%22%3E%40JoakimHGjerde%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBetter%20if%20you%20provide%20sample%20file%20instead%20of%20screenshot%2C%20but%20let%20try%20this%20way.%20I'd%20suggest%20Power%20Query%3C%2FP%3E%0A%3CP%3E-%20yes%2C%20you%20need%20Date%20table%2C%20but%20don't%20generate%20in%20Excel%20sheet%2C%20you%20may%20find%20a%20lot%20of%20samples%20how%20to%20do%20such%20table%20by%20Power%20Query%3C%2FP%3E%0A%3CP%3E-%20if%20second%20table%20is%20Source%2C%20reference%20on%20it%2C%20keep%20only%20Accounts%20column%2C%20remove%20duplicates%2C%20add%20custom%20column%20with%20%3DDate%20table%2C%20expand%20it%20on%20dates%3C%2FP%3E%0A%3CP%3E-%20Merge%20(left%20join)%20this%20table%20with%20Source%20on%20Account%20and%20Date%2C%20expand%20Balance%3C%2FP%3E%0A%3CP%3E-%20fix%20the%20table%20in%20memory%20by%20adding%20Index%20column%20and%20Group%20By%20on%20Accounts%20without%20aggregation%3C%2FP%3E%0A%3CP%3E-%20in%20formula%20bar%20change%20%3CSTRONG%3Eeach%20_%3C%2FSTRONG%3E%20on%26nbsp%3B%3CSTRONG%3Eeach%20Table.FillDown(_%2C%7B%22Balance%22%7D)%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E-%20expand%20column%20with%20grouped%20result%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20you%20may%20load%20query%20to%20data%20model%20and%20create%20PivotTable%20from%20it%3B%20or%20pivot%20query%20and%20return%20table%20to%20sheet%2C%20etc.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1935583%22%20slang%3D%22en-US%22%3ERe%3A%20PQ%20%2F%20Data%20Model%20-%20Turning%20non%20consecutive%20days%20into%20consecutive%20with%20the%20value%20from%20previous%20da%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1935583%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3BThank%20you%2C%20that%20worked%20like%20a%20charm.%20And%20apologize%20for%20not%20incl.%20the%20actual%20sample%20file.%20Created%20a%20quick%20example%20as%20the%20data%20used%20in%20the%20model%20is%20sensitive.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi,

I have a very particular use case, where I have a data set with account balances and a data set with all calendar dates for a period. The account balances however may only contain some of the dates. I want to use return a Table or a Pivot Table with Balances for all calendar dates where the blanks are is the exact balance of the previous balance known.

 

Have tried to visualize a simple use case below, where I would like as an example Konto 1 to return 400 for both 04.01.2020 and 05.01.2020, etc.

 

Have tried to solve this using DAX but no luck. Will do this on relatively large datasets (100 accounts * 365 days) and not really to concerned whether it is solved in the Query or in DAX etc. as long as it handles the amount of data.

 

Any suggestions would be much appreciated.

 

Image.JPG

3 Replies
Best Response confirmed by JoakimHGjerde (New Contributor)
Solution

@JoakimHGjerde 

Better if you provide sample file instead of screenshot, but let try this way. I'd suggest Power Query

- yes, you need Date table, but don't generate in Excel sheet, you may find a lot of samples how to do such table by Power Query

- if second table is Source, reference on it, keep only Accounts column, remove duplicates, add custom column with =Date table, expand it on dates

- Merge (left join) this table with Source on Account and Date, expand Balance

- fix the table in memory by adding Index column and Group By on Accounts without aggregation

- in formula bar change each _ on each Table.FillDown(_,{"Balance"})

- expand column with grouped result

 

Now you may load query to data model and create PivotTable from it; or pivot query and return table to sheet, etc.

@Sergei Baklan Thank you, that worked like a charm. And apologize for not incl. the actual sample file. Created a quick example as the data used in the model is sensitive. 

@JoakimHGjerde , you are welcome.

As a sample I mean only exactly the same as on your screenshot, but as file, nothing more. Anyway, good to know it works, thank you for the update.