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

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
carlottaf
Frequent Visitor

Use SELECTEDVALUE in a measure

Hi everyone!

I have a table showing Sales by Client and I am trying to filter it by Year, Month.
I also have to put in this table the same sale measure calculated on a different period that is chosen by the user using the slicers.

 

To achieve this, I have 4 filters:

Year

Month

Year_Comparison

Month_Comparison

 

The matrix I have is not filtered directly by any of the slicers. Because of this, I want to filter the sales measure using the SELECTEDVALUE function.

 

This is the measure I created:

Sales =
Var Calendar_Year = SELECTEDVALUE(Calendar[Year)
Return
CALCULATE(SUM('Documento-Riga'[Netto riga]),
FILTER('Documento-Riga', YEAR('Documento-Riga'[Data]) = Calendar_Year),
)

However when I put this on the matrix, it is empty.

I also tried creating another measure:
Selected_Year = SELECTEDVALUE(Calendar[Year)
 
Then I did:
Sales =
Var Calendar_Year = [Selected_Year]
Return
CALCULATE(SUM('Documento-Riga'[Netto riga]),
FILTER('Documento-Riga', YEAR('Documento-Riga'[Data]) = Calendar_Year),
)
 
But nothing changed. It works when I hard-encode the year on the measure, like this:
Sales =
Var Calendar_Year = 2021
Return
CALCULATE(SUM('Documento-Riga'[Netto riga]),
FILTER('Documento-Riga', YEAR('Documento-Riga'[Data]) = Calendar_Year),
)
 
I also tried using ALLSELECTED(Calendar[Year]), and it works, but in the matrix it shows all the years and I want only the one I select.

Can you help me undesrtand why and how to fix this?

Thanks,
Carlotta.
4 REPLIES 4
amitchandak
Super User
Super User

@carlottaf , Are you selecting any value from the slicer?

 

 

Try like

Selected_Year = maxx(allselected(Calendar), Calendar[Year)

Then
Sales =
Var Calendar_Year = [Selected_Year]
Return
CALCULATE(SUM('Documento-Riga'[Netto riga]),
FILTER('Documento-Riga', YEAR('Documento-Riga'[Data]) = Calendar_Year),
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

I tried, but it returns the wrong calculation. 

Anonymous
Not applicable

Hi @carlottaf,

Selectedvalue function can be used to get the current row contents(include filter effects), it will return blank if the current row content has multiple values. You need to add the 'alternate Result' parameter to handle multiple value results.

SELECTEDVALUE function - DAX | Microsoft Docs

BTW, Can you please share some dummy data that keep raw data structure with expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

I am selecting only one Year in the slicer, 2021.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors