cancel
Showing results for
Did you mean:
carloscabreraq Regular Visitor

## Add calculated item to a Matrix

Hello,

i am using a matrix to group my data like this. the last 3 columns are measures.

I want to add calculates items(yellow rows) and get a result like this. How can i do it?

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted Community Support Team

## Re: Add calculated item to a Matrix

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. 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", 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] )
``` ```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 Community Support Team

## Re: Add calculated item to a Matrix

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

Maggie

4 REPLIES 4
Highlighted Community Support Team

## Re: Add calculated item to a Matrix

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. 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", 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] )
``` ```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

carloscabreraq Regular Visitor

## 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 Team

## Re: Add calculated item to a Matrix

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

Maggie

carloscabreraq Regular Visitor

## Re: Add calculated item to a Matrix

Thanks @v-juanli-msft

Announcements #### Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future. Learn the answers to some of the questions asked during the Amanda Triple A event. #### October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.  Top Kudoed Authors
Users Online
Currently online: 370 members 3,538 guests
Recent signins:
• mattileppanen • pbc • AB-BI • ale_leme • maximus84 • KoenVdB • lucamilanesi • lucamilanesi • Dustin_Gunnells • pureillusion • SibaniS • AndrewKaddas • GG77 • msportbase 