cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
carloscabreraq Helper I
Helper I

Add calculated item to a Matrix

Hello,

i am using a matrix to group my data like this.

Dashboard.JPG

the last 3 columns are measures.

I want to add calculates items(yellow rows) and get a result like this.

dashboard resultado.JPG

 

How can i do it? 

thanks for your help.

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Community Support
Community Support

Re: Add calculated item to a Matrix

Hi @carloscabreraq

There is no direct way in Power BI to achieve this requirment.

Here is a workaround

 

1.Create a new table with the same structure as your "transaccion" table,

This is to say, the new table has the same numbers of columns and the same column names, but only keep two rows and let the cells filled with 0 except the [tipo] column.

9.png

I create this table using Excel:

Copy the whole "transaccion" table, then paste in the Excel, 

delete all rows from this table in Excel, but keep the column header,

fill "e","f" in the [tipo] column as above, fill 0 in other cells (only create two rows)

 

2. import created table above into Power BI, the append this table to "transaccion" table in Power Query

Open Queries editor,

in "transaccion" table, select Home->"Append", 

10.png

then Close&&Apply, go to Report view

 

3. create measures based on the three measures

Last Month1 =
VAR sub_e =
    CALCULATE ( [Last Month], FILTER ( ALL ( transaccion ), [tipo] = "d" ) )
        - CALCULATE ( [Last Month], FILTER ( ALL ( transaccion ), [tipo] = "c" ) )
VAR sub_f =
    CALCULATE ( [Last Month], FILTER ( ALL ( transaccion ), [tipo] = "a" ) )
        + sub_e
RETURN
    SWITCH ( MAX ( [tipo] ), "e", sub_e, "f", sub_f, [Last Month] )

11.png

Last MTD1 =
VAR sub_e =
    CALCULATE ( [Last MTD], FILTER ( ALL ( transaccion ), [tipo] = "d" ) )
        - CALCULATE ( [Last MTD], FILTER ( ALL ( transaccion ), [tipo] = "c" ) )
VAR sub_f =
    CALCULATE ( [Last MTD], FILTER ( ALL ( transaccion ), [tipo] = "a" ) )
        + sub_e
RETURN
    SWITCH ( MAX ( [tipo] ), "e", sub_e, "f", sub_f, [Last MTD] )


MTD1 =
VAR sub_e =
    CALCULATE ( [MTD], FILTER ( ALL ( transaccion ), [tipo] = "d" ) )
        - CALCULATE ( [MTD], FILTER ( ALL ( transaccion ), [tipo] = "c" ) )
VAR sub_f =
    CALCULATE ( [MTD], FILTER ( ALL ( transaccion ), [tipo] = "a" ) )
        + sub_e
RETURN
    SWITCH ( MAX ( [tipo] ), "e", sub_e, "f", sub_f, [MTD] )

 

Best Regards

Maggie

 

 

View solution in original post

Community Support
Community Support

Re: Add calculated item to a Matrix

Hi @carloscabreraq

To let this measure work with slicer, change "ALL"to "ALLSELECTED".

 

Best Regrads

Maggie

View solution in original post

4 REPLIES 4
Community Support
Community Support

Re: Add calculated item to a Matrix

Hi @carloscabreraq

There is no direct way in Power BI to achieve this requirment.

Here is a workaround

 

1.Create a new table with the same structure as your "transaccion" table,

This is to say, the new table has the same numbers of columns and the same column names, but only keep two rows and let the cells filled with 0 except the [tipo] column.

9.png

I create this table using Excel:

Copy the whole "transaccion" table, then paste in the Excel, 

delete all rows from this table in Excel, but keep the column header,

fill "e","f" in the [tipo] column as above, fill 0 in other cells (only create two rows)

 

2. import created table above into Power BI, the append this table to "transaccion" table in Power Query

Open Queries editor,

in "transaccion" table, select Home->"Append", 

10.png

then Close&&Apply, go to Report view

 

3. create measures based on the three measures

Last Month1 =
VAR sub_e =
    CALCULATE ( [Last Month], FILTER ( ALL ( transaccion ), [tipo] = "d" ) )
        - CALCULATE ( [Last Month], FILTER ( ALL ( transaccion ), [tipo] = "c" ) )
VAR sub_f =
    CALCULATE ( [Last Month], FILTER ( ALL ( transaccion ), [tipo] = "a" ) )
        + sub_e
RETURN
    SWITCH ( MAX ( [tipo] ), "e", sub_e, "f", sub_f, [Last Month] )

11.png

Last MTD1 =
VAR sub_e =
    CALCULATE ( [Last MTD], FILTER ( ALL ( transaccion ), [tipo] = "d" ) )
        - CALCULATE ( [Last MTD], FILTER ( ALL ( transaccion ), [tipo] = "c" ) )
VAR sub_f =
    CALCULATE ( [Last MTD], FILTER ( ALL ( transaccion ), [tipo] = "a" ) )
        + sub_e
RETURN
    SWITCH ( MAX ( [tipo] ), "e", sub_e, "f", sub_f, [Last MTD] )


MTD1 =
VAR sub_e =
    CALCULATE ( [MTD], FILTER ( ALL ( transaccion ), [tipo] = "d" ) )
        - CALCULATE ( [MTD], FILTER ( ALL ( transaccion ), [tipo] = "c" ) )
VAR sub_f =
    CALCULATE ( [MTD], FILTER ( ALL ( transaccion ), [tipo] = "a" ) )
        + sub_e
RETURN
    SWITCH ( MAX ( [tipo] ), "e", sub_e, "f", sub_f, [MTD] )

 

Best Regards

Maggie

 

 

View solution in original post

carloscabreraq Helper I
Helper I

Re: Add calculated item to a Matrix

Hi @v-juanli-msft when i use a Filter with a slicer, the new measures doesnt work, they get me the TOTAL. I think it is because the

 FILTER ( ALL ( transaccion ),)

 

Regards

Carlos CQ

Community Support
Community Support

Re: Add calculated item to a Matrix

Hi @carloscabreraq

To let this measure work with slicer, change "ALL"to "ALLSELECTED".

 

Best Regrads

Maggie

View solution in original post

carloscabreraq Helper I
Helper I

Re: Add calculated item to a Matrix

Thanks @v-juanli-msft

Helpful resources

Announcements
New Ranks Launched March 24th!

New Ranks Launched March 24th!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power BI Community!

‘Better Together’ Contest Finalists Announced!

‘Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

Arun 'Triple A' Event Video, Q&A, and Slides

Arun 'Triple A' Event Video, Q&A, and Slides

Missed the Arun 'Triple A' event or want to revisit it? We've got you covered! Check out the video, Q&A, and slides now.

Join THE global Microsoft Power Platform event series.

Join THE global Power Platform event series.

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors