Forum Discussion

Elglouton's avatar
Elglouton
Regular Visitor
2 years ago
Solved

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
  • Wilson_'s avatar
    Wilson_
    2 years ago

    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.

  • 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

11 Replies

  • Wilson_'s avatar
    Wilson_
    Memorable Member

    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.

    • Elglouton's avatar
      Elglouton
      Regular Visitor

      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

      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.

      • Wilson_'s avatar
        Wilson_
        Memorable Member

        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.