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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Lukas90
New Member

DAX

Hi,

 

I need to write a measure that will be calculated on the chart only for the smaller of the selected years. That is, if I select 2023 and 2024 on the slicer, I only want to see the value for 2023 (i.e. one bar) on the chart. On the X axis there will still be 2023 and 2024 because they are needed for other measures. That is, I need remove one right, blue bar (gray is another measure that counts well).

 

Thanks!

 

Lukas90_0-1726228351130.png

 

1 ACCEPTED SOLUTION

yes you are right. The issue was due to an oversight on my part. you should write it as follows...

 

var min_year = calculate( min ('date' [year]) , allselected ('date' [year]))

View solution in original post

9 REPLIES 9
dk_dk
Super User
Super User

Hi @Lukas90 

I have a half solution that works, but will keep all the years on the x axis visible at all times:

 

SelectiveVis table has a Year column and two measures (Correct and Wrong, correct is the one you want to show on all years, wrong is the one you want to show only on the min year) based on 2 columns

I create a separate table (yrhlp) that only has one year column.

Then a third measure:

HiddenMeasure =

VAR minYear = MIN(yrhlp[yr])

VAR val = CALCULATE([Wrong Measure],SelectiveVis[Year]=minYear)

RETURN
IF(MAX(SelectiveVis[Year])=minYear,val,"")



Then configure relationship as follows:

 

dk_dk_0-1726231534637.png

 

In your visual, use the year from SelectiveVis as the axis, but in your slicer use the year from yrhlp.


Here is how it looks:

dk_dk_1-1726231628462.png

 

 

dk_dk_2-1726231648801.png

 

 

Couldnt find a way to get rid of the blank 2022 column unfortunately. But in terms of showing the measure only on the min year, it does what you were after.

 

Hope it helps a little!






Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Lukas90
New Member

@Selva-Salimi

 

I have dim date. 

 

If I choose two years I still see two blue bars unfortunately:(

@Lukas90 

 

so you should write it as follows:

var min_year = calculate( min ('date' [year]) , allselected ('date' , 'date' [year]))

 

If this post helps, then I would appreciate a thumbs up and mark it as the solution to help the other members find it more quickly. 

Still doesn't work:(

@Lukas90 

 

I test this measure and it works!. what is the table of X axis (years)?

I removed table reference and now it works! Many Thanks!

Yes, for this second option I got "Multiple arguments are not allowed in the ALLSELECTED function when the first argument is a table reference."

yes you are right. The issue was due to an oversight on my part. you should write it as follows...

 

var min_year = calculate( min ('date' [year]) , allselected ('date' [year]))

Selva-Salimi
Solution Supplier
Solution Supplier

Hi @Lukas90 

 

you can update your measure as follows:

measure _min :=

var min_year = min ('date' [year]) (if you dont have dim date you should use all or allselected)

return

if (selectedvalue(year) = min_year , blue_measure , 0 )

 

If this post helps, then I would appreciate a thumbs up and mark it as the solution to help the other members find it more quickly. 

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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