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

Return blank in dax measure if data is missing

Hello!

 

I have IndicatorsData table with historical data of actual coefficients across different indicator names.

 

I want to create a table visual, which will return the average actual coefficient for each indicator name, but for the last selected year only. So, if there is a multiple selection in a year slicer, the table should display the average coefficient only for the maximum of selected years. I created a measure 

last_selected_year = MAXX(ALLSELECTED('indicatorsData'[year]),'indicatorsData'[year]).

 

However, there are missing data. And of there is no data for last_selected_year for a particular indicator, I want the table visual to display nothing.

 

I created a measure for calculating the avg coefficient. But in case of missing data it returns last non blank value, while I want it to return blank or at least 0.

 

actual_coeff_last_year = CALCULATE(AVERAGE(indicatorsData[actual_coeff]), FILTER(indicatorsData, indicatorsData[year] = [last_selected_year]))

 

Pbix file to play with.

 

 

 

1 ACCEPTED SOLUTION
Ahmedx
Super User
Super User

Is this what you are looking for?
Screen Capture #312.png

View solution in original post

3 REPLIES 3
Ahmedx
Super User
Super User

read a book "Power BI DAX Simplified"  :- Chapter 7: Caution When Using Variables in DAX and Power BI

Ahmedx
Super User
Super User

Is this what you are looking for?
Screen Capture #312.png

yes, exactly! omg thanks!

could you pls explain why if I create a measure "last_selected_year" outside the "actual_coeff_last_year", the latter behaves differently than if we would create a varibale "last_selected_year" inside the "actual_coeff_last_year"? So counterintuitive...

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.