cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sparkymark75
Frequent Visitor

Sum count of rows for prior date range

I have data which when I can get into this form using a summarize;

 

2019-05-31_14-57-59.png

 

VAR Product = SELECTEDVALUE(Products[GenericDescription])
VAR Module = SELECTEDVALUE(ModuleFaults[new_moduletype])
VAR FailType = SELECTEDVALUE(ModuleFaults[new_fault])

VAR FailuresGrouped = SUMMARIZE(
                ALL('ModuleFaults'),
                Incident[CompletedMonthYear],
                Incident[ITMGEDSC],
                ModuleFaults[new_moduletype],
                ModuleFaults[new_fault],
                "MonthlyFailures",
                COUNTROWS(ModuleFaults)
            )

 

 

I'm trying to create a measure which will show a sum of the MonthlyFailures column (per Widget, Module, Fault) for each MonthYear row for the previous 3 months. So the output should look like so...


2019-05-31_15-01-02.png

 

 

 

 

I've tried doing a SUMX but I just keep getting the total number of rows back.

 

 

VAR FailCountByType = SUMX(
        FILTER(FailuresGrouped,
            Incident[CompletedMonthYear] >= FIRSTDATE(DATEADD('Incident'[CompletedMonthYear], -3, MONTH)) &&
            Incident[CompletedMonthYear] <= EOMONTH(Incident[CompletedMonthYear], 0) &&
            ModuleFaults[new_moduletype] = Module &&
            ModuleFaults[new_fault] = FailType &&
            Incident[ITMGEDSC] = Product
        ),
    [MonthlyFailures]
)

 

 

3 REPLIES 3
Community Support
Community Support

Re: Sum count of rows for prior date range

Hi @sparkymark75 ,

 

One sample for your reference. Please check the following steps as below.

 

1. To create a calculated column in your summrized table.

rank = 
RANKX ( ALL ( 'Table1' ), Table1[Month Year],, ASC, DENSE )

2. To create a measure to get the excepted result we need.

Measure 2 = 
VAR ran =
    MAX ( Table1[rank] ) - 2
RETURN
    CALCULATE (
        SUM ( Table1[MonthFailures] ),
        FILTER (
            ALLSELECTED ( Table1 ),
            Table1[rank] >= ran
                && Table1[rank] <= MAX ( Table1[rank] )
        )
    )

Capture.PNG

Pbix as attached.

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.
sparkymark75
Frequent Visitor

Re: Sum count of rows for prior date range

Thanks for replying. I'm guessing I didn't word my question as clearly as I should have. The summary table is calculated inline in the measure as a variable, e.g.

 

VAR FailuresGrouped = SUMMARIZE(
                FILTER(ALL('ModuleFaults'), ModuleFaults[CaseCompletedOn] <> BLANK()),
                Incident[CompletedMonthYear],
                Incident[ITMGEDSC],
                ModuleFaults[new_moduletype],
                ModuleFaults[new_fault],
                "MonthlyFailures",
                COUNTROWS(ModuleFaults)
            )

Is it possible to use the RANKX on a table in a variable and then the subsequent measure code you have? 

Community Support
Community Support

Re: Sum count of rows for prior date range

Hi @sparkymark75 ,

 

ADDCOLUMNS should work, please have a try. Could you please share your sample data to me ?
 
Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

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.

Top Solution Authors
Top Kudoed Authors