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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Generate row for current month using values from previous month if not available

Hi All,

 

I have requirement where i need to bring in previous month project information in current month if not availble along with other values. I'm doing this because i want YTD data in months. But when i checked YTD data value was not matching because projects which got closed was not having data in current month and hence YTD number was not matching with actual YTD numbers. In short actual YTD let's say when I select Jan + Feb if i get 100, then with new measure which i have created i should get this 100 when i select Feb only. For example 

DateYearSectorProjectActivity CurrencyGross RevenueDirect ExpensesStaff CostsOHonSubConsultant
01-01-19 0:002019IIDP1INR83.22   

 

Project P1 got closed in Jan month and there is no entry in Feb Month so i would like to basically generate or copy Jan month row as is for Feb and subsequent months. So that my YTD number will match. Do let me know if you need more information or in case of any queries. 

 

Meanwhile i tried with 

FullTable =
ADDCOLUMNS(
CALENDAR(STARTOFMONTH('Loss Factor'[Date]), ENDOFMONTH('Loss Factor'[Date])),
"Gross Revenue",
LOOKUPVALUE(
'Loss Factor'[Gross Revenue],
'Loss Factor'[Date],
MAXX(
FILTER('Loss Factor', 'Loss Factor'[Date] <= EARLIER([Date])),
[Date]
)
)
)
This should be dynamic.
2 REPLIES 2
kentyler
Solution Sage
Solution Sage

The generic answer for wanting to "copy the previous row" in DAX is to do it BEFORE you load the data. Here's the best explanation I've found about it: 

Alternatively, and arguably a better approach, you may use Power Query before your data hits the DAX engine. Power Query bypasses the issue with DAX (discussed in the next two paragraphs) in multiple ways - the most elegant (although advanced - there's simpler methods) would List.Accumulate().

However, and every other post missed this, the answer to "Is it possible to have a Calculated DAX column that uses the previous rows calculated value as an input? " is NO. This is a recursive question. DAX cannot do recursion.

The reason why is simple: when the engine is compiling your calculated columns the smallest atomic unit in the DAX engine is a column - not a cell, like Excel. DAX cannot calculate the first cell in a column, then the next, then the next etc because it has no concept of a cell. It calculates the entire column at once because there is nothing smaller. This is a very important concept to understand when first learning DAX.

https://www.reddit.com/r/PowerBI/comments/9m0b49/dax_refer_to_previous_row_of_same_column/





Did this post answer your question? Mark it as a solution so others can find it!

Help when you know. Ask when you don't!




Join the conversation at We Talk BI find out more about me at Slow BI


Anonymous
Not applicable

@kentyler Thanks for the explanation, it clarified my doubt.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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