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 Based On Second Biggest Value From Another Column

Hi everyone,

 

I have a table that contains many rows. One of the columns is period (YYYYMMDD). Another column is the Sales Amount.

 

What I want to do is to have a column (measure?) that will show me the sales amount for the second "biggest" (aka max) month. Note that many rows will have the same period.

 

Index | Sales Amount | Period
01----------------100-20200130
02----------------150-20200130
03----------------250-20200130

04----------------500-20200130

05----------------500-20200228

06----------------500-20200228

07---------------1000-20200228

 

So, I want to have a table like this:

 

   Period   |  Sales  | Sales vPM
20200228 - 2000 -  1000

 

I do have a measure RANK 

RANK =
RANKX (
ALLSELECTED ( 'All BPOC Reports'[Period_Number] ),
CALCULATE ( MAX('All BPOC Reports'[Period_Number] ) ),
,
DESC,
DENSE
)
 
But I don't know what to do next...

 

thank you for the help!

1 ACCEPTED SOLUTION
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

You can use PARALLELPERIOD function

https://docs.microsoft.com/en-us/dax/parallelperiod-function-dax

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

View solution in original post

4 REPLIES 4
Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

You can use PARALLELPERIOD function

https://docs.microsoft.com/en-us/dax/parallelperiod-function-dax

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Anonymous
Not applicable

you are genius @Mariusz 🙂 

Anonymous
Not applicable

Actually I came across a similar challenge.

 

The metric you suggested: [Unbilled-Previous-Month = CALCULATE(SUM('All BPOC Reports'[Unbilled]), PARALLELPERIOD('All BPOC Reports'[SourceDate],-1,MONTH)] is working great if I have a table and one of my columns is Dates.

 

However, what I also would like to have is a stand-alone multi-row card that will always show me two things:

- Current Month Unbilled [Highest Month, Max]

- Previous Month Unbilled*

 

*Previous Month Unbiled (formula above) is showing me the total of all Unbilled values from my table. However, if I select one of the specific Dates, then it will show correctly.

 

My desired output is:

a) if nothing is selected, show me the Current Month Unbilled (Highest | Max Month) & Previous Month Unbilled

b) if I select 1/31/2020, show me the Current Month Unbilled (75M) & Previous Month Unbilled (60M)

 

 

Point b) is working well, I just need to fix the point a) somehow. I was thinking about embedding MAX formula or creating a var with M-1, but I got a bit lost...

 

Unbilled_01.PNG

Anonymous
Not applicable

Ok, below will solve the issue. Not sure if that's the easiest way, but it works.

 

Unbilled-Previous-Month-02 =
VAR Period01 = [Measure-00]
RETURN
if([Measure-00]<>0,calculate(sum('All BPOC Reports'[Unbilled]),'All BPOC Reports'[SourceDate]=Period01),[Unbilled-Previous-Month])
 
Measure-00 =
VAR Date1 = [Max-Period-01]
VAR Date2 = CALCULATE(MAX('All BPOC Reports'[SourceDate]),FILTER('All BPOC Reports','All BPOC Reports'[SourceDate]<Date1))
RETURN Date2

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.