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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Amaze23
Regular Visitor

Modify the DAX for LASTNONBLANKVALUE for a Non Date Context

Hello,
There is a DAX query which i am unable to resolve.

Amaze23_0-1642607406335.png

 


Background of the screenshot:  In the above screenshot we have date for conferences that happens almost every year.

Conf Code - Conference Code assigned to a conference for a particular year and changes slightly every year
Accu Code - It is unique to every Conference and remains same.
Conf Year - Year in which conference has happened.
# Individuals Retained - it represents the no. of attendees got retained.
# Individuals Retained PY - it represents the no. of attendees got retained from past year.

 
Query & Desired Result:  Amaze23_1-1642607406347.png

 

Suppose a new conference "CET22A" happens this year i.e. "2022" but the "# Individuals Retained" measure is blank then "# Individuals Retained PY" measure should show the last non blank value of "# Individuals Retained" measure which is 24 in above case and repeat it until "# Individuals Retained" has a value as in the screenshot for this particular conference only.

Current Measure in use:

# of Individuals Retained PY =
var py = max('Dim - Conferences'[Conf Year]) -1
var acc = MAX('Dim - Conferences'[Accu Code])
return
if(HASONEVALUE('Dim - Conferences'[Conf Code]),
CALCULATE( [# of Individuals Retained],
filter(all('Dim - Conferences'),
'Dim - Conferences'[Conf Year]= py && 'Dim - Conferences'[Accu Code]=acc) ),
CALCULATE([# of Individuals Retained],
filter(all('Dim - Conferences'),
'Dim - Conferences'[Conf Year]= py )))

I cant share the data due to privacy reasons.

Best Regards

#DAX #Desktop #DAXissues
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Amaze23 , Try a measure like

calculate(lastnonblankvalue(Table[Year],[# Individuals Retained]), filter(all(Table), [Accu Code] = max([Accu Code] ) && [Year] <= Max(Table[Year])))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Amaze23 , Try a measure like

calculate(lastnonblankvalue(Table[Year],[# Individuals Retained]), filter(all(Table), [Accu Code] = max([Accu Code] ) && [Year] <= Max(Table[Year])))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@amitchandak : Thanks, it worked great! you used lastnonblankvalue & tweaked use of conf year as Conf year <= Max (conf year), can you put light on this ?

Actually it looks simple but i am not able to get it.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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