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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
13havya
Frequent Visitor

Dynamically calculate sum for current and historical data

Hi,

 

I am trying to develop a measure that returns the amount of money held in unresolved files. The metric needs to show the values at any point in time, and not just the live data. To facilitate that, we have merged a live data and cutoff data report in our fact table. 

The measure looks something like this 


$ Debt = 
VAR Live = CALCULATE (SUMX(FILTER(Fact table, report = "Live" && {conditions}), debt_amt)), userelationship(timestamp, date))

Var Historical = CALCULATE (SUMX(FILTER(Fact table, report = "Historical" && {conditions}), debt_amt)),userelationship(timestamp, date))

RETURN 

IF (YEAR(Max(Dim_Date[Date])) = YEAR(TODAY) && MONTH(MAX(Dim_Date[Date])) = MONTH(TODAY), Live, Historical)

 

The measure works as intended when viewing month by month, but the problem arises when trying to view it over different time dimensions i.e quarterly/half yearly basis - where it sums up the debt over the time period and returns a total value. 

However, I would like the measure to return the value at the last point in time if selected over a larger time period (i.e. if selected over a quarter, it should show the debt value at the last date in that quarter, and not add up the 3 months). 

 

Any tips and suggestions would be greatly appreciated. 

 

Thanks 

1 ACCEPTED SOLUTION
xifeng_L
Super User
Super User

Hi @13havya ,

 

You can try below measure.

 

$ Debt = 
LASTNONBLANKVALUE(
    Dim_Date[Date], // use the row label field of matrix.

    VAR Live = CALCULATE (SUMX(FILTER(Fact table, report = "Live" && {conditions}), debt_amt), userelationship(timestamp, date))

    Var Historical = CALCULATE (SUMX(FILTER(Fact table, report = "Historical" && {conditions}), debt_amt)),userelationship(timestamp, date))

    RETURN 

    IF (YEAR(Max(Dim_Date[Date])) = YEAR(TODAY) && MONTH(MAX(Dim_Date[Date])) = MONTH(TODAY), Live, Historical)
)

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

 

 

View solution in original post

1 REPLY 1
xifeng_L
Super User
Super User

Hi @13havya ,

 

You can try below measure.

 

$ Debt = 
LASTNONBLANKVALUE(
    Dim_Date[Date], // use the row label field of matrix.

    VAR Live = CALCULATE (SUMX(FILTER(Fact table, report = "Live" && {conditions}), debt_amt), userelationship(timestamp, date))

    Var Historical = CALCULATE (SUMX(FILTER(Fact table, report = "Historical" && {conditions}), debt_amt)),userelationship(timestamp, date))

    RETURN 

    IF (YEAR(Max(Dim_Date[Date])) = YEAR(TODAY) && MONTH(MAX(Dim_Date[Date])) = MONTH(TODAY), Live, Historical)
)

 

 

Did I answer your question? If yes, pls mark my post as a solution and appreciate your Kudos !

 

Thank you~

 

 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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