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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Elglouton
Regular Visitor

Selected value on Dax in switch

Hello,

 

I use the value captured by the Selectedvalue function as a variable to perform standard calculations, it works perfectly, but I wanted to embed it in a switch and the function returned the alternatResult.

parameter table 

Boites Max = GENERATESERIES(500,500000,100)
Value
Valeur Boites Max = SELECTEDVALUE('Boites Max'[Boites Max],0)
SWITCH fonction
BoiteJourPrev_L1 = SWITCH (
         T_DATE_[JoursVacances],
         False,[Valeur Boites Max],0
        )
Same with 
BoiteCumulPrev_L1M2 =
CALCULATE(
TOTALMTD(
    ([Valeur Boites Max]),T_DATE_[Date],T_DATE_[JoursVacances]=False())
    )
I use this measure to write the value to the table if the date is worked on
2 ACCEPTED SOLUTIONS

Elglouton,

 

Ah, it looks like the issue is you added it as a calculated column. It should be a measure.


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

 

P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on Upwork or DM me directly on here! I would love to clear up your Power BI headaches.




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

Proud to be a Super User!





View solution in original post

Hello,

Halala, in fact, it was that simple.

I didn't think I could make a graph with a measure because for me it's a unique value.

Sorry for the time you spent on this topic and thanks again

View solution in original post

11 REPLIES 11
Wilson_
Super User
Super User

Hi Elglouton,

 

It's unclear to me from your measure syntax what you're trying to accomplish. For example, your BoiteJourPrev_L1 measure looks like it's missing something and doesn't make sense logically. Check out this documentation on SWITCH and see if it helps.

 

If you're still having trouble, please explain in words what you're actually trying to calculate in your two measures.




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

Proud to be a Super User!





Hello
thank you for your reply.
In my company we make boxes and we have a minimum quantity of boxes to produce per day to be in the forecast. I monitor this via a monthly graph which compares the boxes to be made with the boxes made.
But depending on the forecast this quantity changes from month to month and I would like to be able to use a segment so that the report users can change it easily.

 

so I have a segment

Elglouton_0-1723007364712.png

and I want to use the selected value of this segment
Valeur Boites Max = SELECTEDVALUE('Boites Max'[Boites Max],0)

to make a monthly accumulation only of the days worked which are given by JoursVacances=True

 

 

I haven't managed to do it directly, so I'm going through an intermediary.

BoiteJourPrev_L1 = SWITCH (
T_DATE_[JoursVacances],
False,[Valeur Boites Max],0
)

then I do my accumulation

BoiteCumulPrev_L1M =
CALCULATE(
TOTALMTD(
sum(T_DATE_[BoiteJourPrev_L1]),T_DATE_[Date],T_DATE_[JoursVacances]=TRUE())
)

When I use it in simple calculations it works and I get back the value of the segment but when I want to integrate it in BoxDayPrev_L1 the calculation works but with the value alternatResult of SELECTEDVALUE()

 

I hope this is clearer
I'm new to PWBi and I'm probably not using the different functions in the right way and I apologise for that.

Hi Elglouton,

 

Thanks for elaborating. I think I understand now. Can you also share a screenshot of your data model? I have an idea of what you need but it depends on your tables and relationships.




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

Proud to be a Super User!





Hello,

perfect if it's easier to understand...
All is in the same table here attached a screen hoping that it is enough

 

Elglouton_0-1723037072734.png

 

Elglouton,

 

In that case, please try:

 

BoiteCumulPrev_L1M =
VAR NumDays =
CALCULATE (
    COUNTROWS ( VALUES ( T_DATE_[Date] ) ), -- counting the number of days
    T_DATE_[JoursVacances] = TRUE(),        -- where JoursVacances is True
    DATESMTD ( T_DATE_[Date] )              -- and days are in month to date
)
VAR Result = NumDays * [Valeur Boites Max]  -- multiplying number of days by your selected value

RETURN Result

 

 

No need for the other intermediary measure, unless you want to reuse it for other measures as well. (I also think based on your screenshots that you meant that T_DATE_[JoursVacances] should be TRUE? It's confusing because the screenshot is saying vacation days are the ones that you're assigning the 7,500. Either T_DATE_[JoursVacances] should be TRUE or the True/False in the screenshot is backwards - or I've misunderstood that part too. :D)


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

 

P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on Upwork or DM me directly on here! I would love to clear up your Power BI headaches.




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

Proud to be a Super User!





Hello
thank you for your answers and your time

in fact the title does not correspond to the result but the error is correct, I have written incorrectly and never changed the title but I must accumulate the days worked.

Your function code saves me the intermediate calculation if I use fixed data for ([Max Boxes Value])

but unfortunately does not solve my problem.

if I use ([Max Box Value]) which is variable data entered from the max box segment it doesn't work.

 

Segement

Elglouton_0-1723124503896.png

 

Elglouton_1-1723124576844.png

 

Elglouton,

 

Can you please share a sample pbix file? (If you don't know how, please check the pinned thread in the forum.)

 

My measure should be using the parameter value you're showing in the second screenshot.




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

Proud to be a Super User!





Hello, 

Attached is a link to a simplified file Fichier simplifié 

the value taken into account is the default value of the segment but not the value entered in the segment.

Thanks

 

Elglouton,

 

Ah, it looks like the issue is you added it as a calculated column. It should be a measure.


----------------------------------
If this post helps, please consider accepting it as the solution to help other members find it quickly. Also, don't forget to hit that thumbs up and subscribe! (Oh, uh, wrong platform?)

 

P.S. Need a more in-depth consultation for your Power BI data modeling or DAX issues? Feel free to hire me on Upwork or DM me directly on here! I would love to clear up your Power BI headaches.




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

Proud to be a Super User!





Hello,

Halala, in fact, it was that simple.

I didn't think I could make a graph with a measure because for me it's a unique value.

Sorry for the time you spent on this topic and thanks again

You're welcome, Elglouton. That's what we're here for! 😄

 

Thanks for the update.




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

Proud to be a Super User!





Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.