Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
1 year ago
Solved

Selectedvalue

Hi,

 

my visual table is always empty because of SelectedValue. I have 2 tables. 

 

Table1: Filter

Group
A

B

C


Table2: Data

CustomerGroupGroup_last_year
AlphaAA
BetaAB
AlphaBA
GammaCC

 

My Measure:

SWITCH (
    TRUE (),
    SELECTEDVALUE ( Table1[Group] ) = "A",
        CALCULATE (
            DISTINCTCOUNTNOBLANK ( Table2[Customer] ),
            FILTER ( Table2, Table2[Group] = "A" && Table2[Group_last_year] = "A" )
        ),
    SELECTEDVALUE ( Table1[Group] ) = "A",
        CALCULATE (
            DISTINCTCOUNTNOBLANK ( Table2[Customer] ),
            FILTER ( Table2, Table2[Group] = "A" && Table2[Group_last_year] = "B" )
        ),
    SELECTEDVALUE ( Table1[Group] ) = "A",
        CALCULATE (
            DISTINCTCOUNTNOBLANK ( Table2[Customer] ),
            FILTER ( Table2, Table2[Group] = "A" && Table2[Group_last_year] = "C" )
        )
)


If I put Table1[Group] and my measure into a table in the visualization, it only shows me data for Group_last_year=A, but not for B and C. Is my measure wrong?

Thanks for any ideas.
 
 
  • Show me in a table(Excel) what you are trying to achieve

    I created a measure for A,B and C, and I got the following table

     

     

    If you need to see the empty lines, you have to tick: Show item with no data

     

  • In fact, you do not need dax to achive that 
    I just set up the following relationship



    Then I added a matrix with the following parameters:

    Rows: Group (if you need from filter)

    Columns: group_last_year

    Values: Count of CUSTOMER_NUMBER

     

     

     

    The blank line is for D et E value

    If you use everything for the excel file you shared

     

11 Replies

  • Anonymous 

    Not sure if I understand your requirement correctly, but one point that I observed is, all your switch conditions are same 

    SELECTEDVALUE ( Table1[Group] ) = "A"

    By default DAX switch statement will evaluate the result of first condition which results to true value. So, I guess for your requirement you need to correct it.

     

    Need a Power BI Consultation? Hire me on Upwork

     

     

     

    Connect on LinkedIn

     

     

     








    Did I answer your question? Mark my post as a solution!
    If I helped you, click on the Thumbs Up to give Kudos.

    Proud to be a Super User!


    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, yes indeed 🙂. My measure is only for Table1[Group]="A". I have another measure only for B and C.

  • Indeed, in you measure you have = "A" everywhere

     

    SWITCH (
        TRUE (),
        SELECTEDVALUE ( Table1[Group] ) = "A",
            CALCULATE (
                DISTINCTCOUNTNOBLANK ( Table2[Customer] ),
                FILTER ( Table2, Table2[Group] = "A" && Table2[Group_last_year] = "A" )
            ),
        SELECTEDVALUE ( Table1[Group] ) = "A",
            CALCULATE (
                DISTINCTCOUNTNOBLANK ( Table2[Customer] ),
                FILTER ( Table2, Table2[Group] = "A" && Table2[Group_last_year] = "B" )
            ),
        SELECTEDVALUE ( Table1[Group] ) = "A",
            CALCULATE (
                DISTINCTCOUNTNOBLANK ( Table2[Customer] ),
                FILTER ( Table2, Table2[Group] = "A" && Table2[Group_last_year] = "C" )
            )
    )

     

    So only the first switch is used, I guess you have to replace the second   SELECTEDVALUE ( Table1[Group] ) = "A", by B and the thirth by C

     

    If it is not what you try to achieve, let me know

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi, yes true. This measure is only for A.  I have another measure only for B and C.

      • Cookistador's avatar
        Cookistador
        Super User

        But your measure for A is wrong, only the first case will be evaluated as you do not have other condition than Table1[Group] = "A"

        What you should do is something like:

         

        Mymeasure = 

        Switch(TRUE(),
        Table1[Group] = "A",MeasureForA,
        Table1[Group] = "B",MeasureForB,
        Table1[Group] = "C",MeasureForC

        )

    • Anonymous's avatar
      Anonymous
      Not applicable

      I want to count the customers from this year vs last year. How many customers in group A were in A last year, how many moved from A to B, ...


      The visualzation should look like that:

       A last yearB last yearC last year
      A110
      B100
      C001