cancel
Showing results for
Did you mean:

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Frequent Visitor

## Sum of measure results

Hello

I am trying to sum the results of the measure that in my model is called "Avg vs Last Avg"

My intention is count how many points increase or decrease.

my expected result is get a count like the red numbers on the right.

All my calculations are measures.

1 ACCEPTED SOLUTION
Community Support

Hi, @Lu1sT0rr3s

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

Table 2(a calcualted table):

``````Table 2 =
SUMMARIZE(
'Table',
'Table'[YearMonth],
"Avg vs Last Month Avg",
IF(
SUM('Table'[Average])<=SUM('Table'[Last Month Average]),
0,1
)
)``````

Calendar(a calculated table):

``````Calendar =
CALENDARAUTO(),
"YearMonth",
YEAR([Date])*100+MONTH([Date])
)``````

You may create a measure as below.

``````Result =
var tab =
SUMMARIZE(
'Table',
'Table'[YearMonth],
"Avg vs Last Month Avg",
IF(
SUM('Table'[Average])<=SUM('Table'[Last Month Average]),
0,1
)
),
"<> max",
CALCULATE(
MAX('Table 2'[YearMonth]),
FILTER(
ALL('Table 2'),
'Table 2'[YearMonth]<EARLIER('Table'[YearMonth])&&
[Avg vs Last Month Avg]<>EARLIER([Avg vs Last Month Avg])
)
),
"= min",
CALCULATE(
MIN('Table 2'[YearMonth]),
FILTER(
ALL('Table 2'),
'Table 2'[YearMonth]<EARLIER('Table'[YearMonth])&&
[Avg vs Last Month Avg]=EARLIER([Avg vs Last Month Avg])
)
)
)
var t =
tab,
"Result",
IF(
[= min]<[<> max],
COUNTROWS(
CALCULATETABLE(
DISTINCT('Calendar'[YearMonth]),
FILTER(
ALL('Calendar'),
[YearMonth]>=[<> max]&&
[YearMonth]<=EARLIER('Table'[YearMonth])
)
)
)-1,
IF(
[= min]>[<> max],
COUNTROWS(
CALCULATETABLE(
DISTINCT('Calendar'[YearMonth]),
FILTER(
ALL('Calendar'),
[YearMonth]>=[= min]&&
[YearMonth]<=EARLIER('Table'[YearMonth])
)
)
),
1
)
)
)
return
SUMX(
t,
[Result]
)``````

Result:

Best Regards

Allan

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

3 REPLIES 3
Community Support

Hi, @Lu1sT0rr3s

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Table:

Table 2(a calcualted table):

``````Table 2 =
SUMMARIZE(
'Table',
'Table'[YearMonth],
"Avg vs Last Month Avg",
IF(
SUM('Table'[Average])<=SUM('Table'[Last Month Average]),
0,1
)
)``````

Calendar(a calculated table):

``````Calendar =
CALENDARAUTO(),
"YearMonth",
YEAR([Date])*100+MONTH([Date])
)``````

You may create a measure as below.

``````Result =
var tab =
SUMMARIZE(
'Table',
'Table'[YearMonth],
"Avg vs Last Month Avg",
IF(
SUM('Table'[Average])<=SUM('Table'[Last Month Average]),
0,1
)
),
"<> max",
CALCULATE(
MAX('Table 2'[YearMonth]),
FILTER(
ALL('Table 2'),
'Table 2'[YearMonth]<EARLIER('Table'[YearMonth])&&
[Avg vs Last Month Avg]<>EARLIER([Avg vs Last Month Avg])
)
),
"= min",
CALCULATE(
MIN('Table 2'[YearMonth]),
FILTER(
ALL('Table 2'),
'Table 2'[YearMonth]<EARLIER('Table'[YearMonth])&&
[Avg vs Last Month Avg]=EARLIER([Avg vs Last Month Avg])
)
)
)
var t =
tab,
"Result",
IF(
[= min]<[<> max],
COUNTROWS(
CALCULATETABLE(
DISTINCT('Calendar'[YearMonth]),
FILTER(
ALL('Calendar'),
[YearMonth]>=[<> max]&&
[YearMonth]<=EARLIER('Table'[YearMonth])
)
)
)-1,
IF(
[= min]>[<> max],
COUNTROWS(
CALCULATETABLE(
DISTINCT('Calendar'[YearMonth]),
FILTER(
ALL('Calendar'),
[YearMonth]>=[= min]&&
[YearMonth]<=EARLIER('Table'[YearMonth])
)
)
),
1
)
)
)
return
SUMX(
t,
[Result]
)``````

Result:

Best Regards

Allan

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Frequent Visitor

Hi, @v-alq-msft

Thanks for take the time to help me out to solve this.

I tryed but it seems that you "Average" and "Last Month Average" are data from a table, but for me are measures, and when I try does not work due does not recognize, in my case, the "average" and "last month Average".

Regards,
LT

Solution Sage

@Lu1sT0rr3s can you provide some more detail about what exactly this desired measure is counting?  It's not clear at all to me from the numbers you provided.

Announcements

#### Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.