Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Lu1sT0rr3s
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.

Lu1sT0rr3s_1-1614292039091.png

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

All my calculations are measures.

 

1 ACCEPTED SOLUTION
v-alq-msft
Community Support
Community Support

Hi, @Lu1sT0rr3s 

 

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

Table:

c1.png

 

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 = 
ADDCOLUMNS(
    CALENDARAUTO(),
    "YearMonth",
    YEAR([Date])*100+MONTH([Date])
)

 

You may create a measure as below.

Result = 
var tab = 
ADDCOLUMNS(
    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 = 
ADDCOLUMNS(
    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:

c2.png

 

Best Regards

Allan

 

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

View solution in original post

3 REPLIES 3
v-alq-msft
Community Support
Community Support

Hi, @Lu1sT0rr3s 

 

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

Table:

c1.png

 

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 = 
ADDCOLUMNS(
    CALENDARAUTO(),
    "YearMonth",
    YEAR([Date])*100+MONTH([Date])
)

 

You may create a measure as below.

Result = 
var tab = 
ADDCOLUMNS(
    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 = 
ADDCOLUMNS(
    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:

c2.png

 

Best Regards

Allan

 

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

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

ebeery
Solution Sage
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.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.