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

LASTNONBLANK value in last 12 months

Hi,

I am currently stuck with one problem in Power BI. What I am looking for is, in the below table, I want to find the latest score for the patients in the last 12 months based on the slicer selection.

apanta_0-1707962115242.png

 


For example, If I select any month after September 2023 to September 2024, the score should show me the result as 2 since the latest Score is 2 on 2/9/2023 but if I select the month as October 2024, the score should come up as zero since there was no data in the last 12 months.

Similarly, when the slicer is selected as July 2023, the result should come up as 3 because the latest score is 2 which was created on 1/6/2023.

Hope I am clear on this.

Thank you!

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@apanta , Create a date table, join it with your date, and use that in visual, slicer, and measure

 

Rolling 12 = CALCULATE(Lastnonblankvalue( Table[Created Date], Max(Table[Core])) , DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-12,MONTH))

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@apanta , Create a date table, join it with your date, and use that in visual, slicer, and measure

 

Rolling 12 = CALCULATE(Lastnonblankvalue( Table[Created Date], Max(Table[Core])) , DATESINPERIOD('Date'[Date],MAX('Date'[Date]),-12,MONTH))

Thank you so much, Amit! It worked like a wonder.

Can I please ask you one more question? In the below table, I want to give a score of 0 to the "Chemical" type. For example, if any month is selected after September 2023 to September 2024 (e.g. October 2023), I want the formula to check which is the latest date and give me a score of 0 as the type is "chemical". The formula you mentioned is working fine, but if I filter out the chemical type then it is capturing the score as 3 from 1/6/2023 which I don't want.

 

apanta_0-1708006957274.png

 

is there an any way to get this result?

Regards

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.