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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Sum Values Where Criteria Is Second Largest

Hi all,

 

I have a table, Pageviews, with three columns: Dates (everyday of the year going back to Jan 2018), Month Ref (six digit codes that reference Dates month and year - so, 201901 for Jan 2019, 201812 for Dec 2018, etc) and finally uPV - pageview data by day.

 

I am trying to generate a measure that dynamically sums all of the uPVs from two months ago. The logical way I can think of doing this is to find the second largest value in Month Ref and sum all corresponding values in uPV. However, there is no LARGE or such formula that I'm aware of so am a bit stuck.

 

Can anyone suggest how I might do this. See below a sample of the data I'm using. In this example, I would expect 11,473 returned as it would be summing everything corresponding to 201812 in Month Ref.

 

TIA,

 

SamB

 

DateMonth RefuPV
01/11/20182018112441
02/11/20182018112164
03/11/20182018111910
04/11/20182018112311
05/11/20182018112060
06/11/20182018111656
07/11/20182018111657
01/12/20182018121922
02/12/20182018121342
03/12/20182018122202
04/12/20182018121611
05/12/20182018121488
06/12/20182018121540
07/12/20182018121368
01/01/20192019012226
02/01/20192019012392
03/01/20192019011938
04/01/20192019011587
05/01/20192019011098
06/01/20192019011332
07/01/20192019011418
1 ACCEPTED SOLUTION
AlB
Super User
Super User

Hi @Anonymous

 

It would probably be easier to create a Date table and operate with it but if you don't want to do that, try this for your measure

 

Measure =
VAR _2MonthsPrior = EDATE ( TODAY (), -2 )
VAR _Month = MONTH ( _2MonthsPrior )
VAR _Year = YEAR ( _2MonthsPrior )
RETURN
    CALCULATE (
        SUM ( Table1[uPV] ),
        YEAR ( Table1[Date] ) = _Year,
        MONTH ( Table1[Date] ) = _Month
    )

View solution in original post

2 REPLIES 2
AlB
Super User
Super User

Hi @Anonymous

 

It would probably be easier to create a Date table and operate with it but if you don't want to do that, try this for your measure

 

Measure =
VAR _2MonthsPrior = EDATE ( TODAY (), -2 )
VAR _Month = MONTH ( _2MonthsPrior )
VAR _Year = YEAR ( _2MonthsPrior )
RETURN
    CALCULATE (
        SUM ( Table1[uPV] ),
        YEAR ( Table1[Date] ) = _Year,
        MONTH ( Table1[Date] ) = _Month
    )
Anonymous
Not applicable

Thank you @AlB - that works perfectly. Much appreciated!

 

SamB

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.