cancel
Showing results for
Did you mean:

## Row level calculation over the dimention

I have to calculate measure DIFF = [PLAN]-[SUMM] over only [Type]  column for every value
and summ only values >0

```[PLAN] = SUM(tab[plan])
[SUMM] = SUM(tab[fact])```

I tried use SUMMARIZECOLUMNS, but I got error "SummarizeColumns() and AddMissingItems() may not be used in this context"

```DIFF =
VAR tab = SUMMARIZECOLUMNS(crm[Type];"diff";[PLAN]-[SUMM]))
RETURN SUMX(tab;[diff])```

and cant understand how to add checking

`[PLAN]-[SUMM] > 0`

in this calculation

1 ACCEPTED SOLUTION
Resolver V

Without having your source dataset to work with, I can only attempt a theoretical solution... have a try and see if this works:

Create a measure called "DIFF (PLAN-SUMM)" :

=VAR isInRow = HASONEVALUE( tab[Type] )

RETURN SUMX(

VALUES( tab[Type] )

,  CALCULATE(

VAR thePlan = SUM(tab[PLAN])

VAR theSumm = SUM(tab[SUMM])

VAR DIFF = thePlan - theSumm

RETURN

IF ( DIFF >= 0, DIFF

, IF( isInRow, DIFF

, 0  )

)

)

)

This measure should work in both the grand total cell and in each row.

When it's in "row mode", all kinds of DIFF's will be displayed, but

when it's in grand total mode, only DIFF>=0 will be included.

3 REPLIES 3
Resolver V

Without having your source dataset to work with, I can only attempt a theoretical solution... have a try and see if this works:

Create a measure called "DIFF (PLAN-SUMM)" :

=VAR isInRow = HASONEVALUE( tab[Type] )

RETURN SUMX(

VALUES( tab[Type] )

,  CALCULATE(

VAR thePlan = SUM(tab[PLAN])

VAR theSumm = SUM(tab[SUMM])

VAR DIFF = thePlan - theSumm

RETURN

IF ( DIFF >= 0, DIFF

, IF( isInRow, DIFF

, 0  )

)

)

)

This measure should work in both the grand total cell and in each row.

When it's in "row mode", all kinds of DIFF's will be displayed, but

when it's in grand total mode, only DIFF>=0 will be included.

@DAX0110, it works as it should! 🙂
Thanks very much

Resolver V

You're welcome!

Announcements

#### Power BI September 2023 Update

Take a look at the September 2023 Power BI update to learn more.

#### Learn Live: Event Series

Join Microsoft Reactor and learn from developers.

#### Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

#### Power Platform Conference-Power BI and Fabric Sessions

Join us Oct 1 - 6 in Las Vegas for the Microsoft Power Platform Conference.

Top Solution Authors
Top Kudoed Authors