Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Switch function not working as intended

Hi All , Im trying to use switch function to dynamically change the columns displayed in a matrix as below

 

How ever when I use it on my filter , Im only seeing the 1st measure dynamically . 

When I select "By Counts" Im expecting to see three columns in the matrix , but its only showing 1 column . Am I missing something?

This is my expected output 

Thanks in Advance!

  • Hi Anonymous ,


    First please create a new table containing the names of these measures.

     

    Then create the following measures and filter the matrix visual.

     

    Mapping = 
    SWITCH (
        MAX ( MatrixColumns[Measure Name] ),
        "Total Orders", [Total Orders],
        "CY Orders Target", [CY Orders Target],
        "CY Orders Target Variance", [CY Orders Target Variance],
        "CY Orders Progress %", [CY Orders Progress %],
        "Total Revenue", [Total Revenue],
        "CY Revenue Target", [CY Revenue Target],
        "CY Revenue Progress %", [CY Revenue Progress %]
    )
    Measure = 
    SWITCH (
        [Selected Measure],
        "By Counts",
            COUNTROWS (
                FILTER (
                    MatrixColumns,
                    MatrixColumns[Measure Name]
                        IN {
                        "Total Orders",
                        "CY Orders Target",
                        "CY Orders Target Variance",
                        "CY Orders Progress %"
                    }
                )
            ),
        "By Revenue",
            COUNTROWS (
                FILTER (
                    MatrixColumns,
                    MatrixColumns[Measure Name]
                        IN { "Total Revenue", "CY Revenue Target", "CY Revenue Progress %" }
                )
            )
    )

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • Anonymous , first 4 and last 3 values are same in switch, they should be different

     

    Or you need more than one measures

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thanks for responding to my question. The logic behind that is, if the user selects "By Counts" I should show the four columns by counts and if "By Revenue" it should show the 4 fields for revenue. Any workaround to show the four corresponding fields based on a single selection? TIA

  • v-kkf-msft's avatar
    v-kkf-msft
    Community Support

    Hi Anonymous ,


    First please create a new table containing the names of these measures.

     

    Then create the following measures and filter the matrix visual.

     

    Mapping = 
    SWITCH (
        MAX ( MatrixColumns[Measure Name] ),
        "Total Orders", [Total Orders],
        "CY Orders Target", [CY Orders Target],
        "CY Orders Target Variance", [CY Orders Target Variance],
        "CY Orders Progress %", [CY Orders Progress %],
        "Total Revenue", [Total Revenue],
        "CY Revenue Target", [CY Revenue Target],
        "CY Revenue Progress %", [CY Revenue Progress %]
    )
    Measure = 
    SWITCH (
        [Selected Measure],
        "By Counts",
            COUNTROWS (
                FILTER (
                    MatrixColumns,
                    MatrixColumns[Measure Name]
                        IN {
                        "Total Orders",
                        "CY Orders Target",
                        "CY Orders Target Variance",
                        "CY Orders Progress %"
                    }
                )
            ),
        "By Revenue",
            COUNTROWS (
                FILTER (
                    MatrixColumns,
                    MatrixColumns[Measure Name]
                        IN { "Total Revenue", "CY Revenue Target", "CY Revenue Progress %" }
                )
            )
    )

     

    If the problem is still not resolved, please provide detailed error information or the expected result you expect. Let me know immediately, looking forward to your reply.
    Best Regards,
    Winniz
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.