Forum Discussion

Xilalus's avatar
Xilalus
Frequent Visitor
4 years ago
Solved

Create complex table with measures

Hey Guys, I am new to using measures in PowerBI and I have this table I created a while a ago, which I would like to recreate using measures. Reasons for this being: - Performance - Better struct...
  • AntonioM's avatar
    4 years ago

    Hi Xilalus,

     

    This is definitely possible. It looks like you've already got most of the steps, just need to create some measures. 

     

    Are IS and PLAN measures already? If they are, you can put both of those in the Values field (with measures not set to rows).

     

     

    Which will give you the columns you need

     

     

    If they are two values from a column (maybe a 'type' column that can be IS or PLAN) then you could put that column in the Columns Field instead, under the month and year.

     

     

    You can use SWITCH and SELECTEDVALUE to find what row the measure is being calculated on and calculate a different value accordingly. For example, 

     

    IS = 
    SWITCH(
        SELECTEDVALUE(Headers[Row Header]),
        "A",
            "each",
        "B",
            "word",
        "C",
            "appears",
        "D",
            "a",
        "E",
            "different",
        "F",
            "row",
        "Intermediate Value 1", 
            17
    )
    PLAN = 
    SWITCH(
        SELECTEDVALUE(Headers[Row Header]),
        "A",
            "plan",
        "B",
            "is",
        "C",
            "in",
        "D",
            "a",
        "E",
            "different",
        "F",
            "column",
        "Intermediate Value 1", 
            10
    )

     

    These two measures give you the table

     

    Instead of the words I've added, you can have a different measure or calculation to evaluate on each row. One thing to note is if you have a mix of text and numbers like above, the entire column will be aligned as one type.

     

    This won't give you a value for the Total, but you can either add an extra 'else' line into the SWITCH, for if there is no match to a row header, or create that row yourself.