Forum Discussion

smore's avatar
smore
Icon for Advocate I rankAdvocate I
4 years ago
Solved

Measure to switch between table columns on visual: returns entire column rows

Table 1: Digital Group No. Dog Weight 1 Java 14 1 Bonnie 20 2 Tater 9 2 Sophie 25   Table 2: Mechanical Group No. Dog Weight 1 Java 13 1 Bonnie 21 2 ...
  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi smore,

    I'd like to suggest you extract and merge the 'no' and 'dog' fields to create a new table with unique value as the bridge link to those tables.

    How to Join Many to Many with a Bridge Table in Power BI | Seer Interactive

    Relationship in Power BI with Multiple Columns - RADACAD

    After these steps, you can create a parameter table with two table names as the source of the slicer, then you can write a measure filter to redirect to different calculation formulas based on selections.

    Weight Measure =
    VAR currDogNO =
        SELECTEDVALUE ( Bridge[DogNO] ) //DogNo are merge from 'Group NO' and 'Dog' field values
    VAR Selection =
        SELECTEDVALUE ( 'Selector'[Source] )//Selecotr with two table Names
    RETURN
        SWITCH (
            Selection,
            "Mechanical",
                CALCULATE (
                    SUM ( Mechanical[Weight] ),
                    FILTER ( ALLSELECTED ( Mechanical ), Mechanical[DogNO] = currDogNO )
                ),
            "Digital",
                CALCULATE (
                    SUM ( Digital[Weight] ),
                    FILTER ( ALLSELECTED ( Digital ), Digital[DogNO] = currDogNO )
                )
        )

    Regards,

    Xiaoxin Sheng