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
gluizqueiroz
Resolver I
Resolver I

How to select value from "previous row" on a filter context with measure to create a % of Growth

On my page, I have sales in 2019 and a slicer filter with months.
Supposing that user selects February, April and June.

 

I need to create a % of Growth:
- Between February and Nothing (Because we don't have anything before).
- Between April and February (Because February is the previous month among selected months).
- Between June and April (Because April is the previous month among selected months).

 

Note that I do not want the previous month direct and yes among the selected ones.

 

First things first. I can create a % of Growth using PREVIOUSMONTH or PREVIOUSYEAR or SAMEPERIODLASTYEAR, but this case is more dynamic. If someone knows how to select previous period among the selected ones, I think I can create my % of Growth on my own.

 

To be more clear, I need something like this:

MonthSalesOnMonthPreviousMonthAmongSelectedSalesOnPreviousMonthAmongSelected% of Growth
feb/201950   
apr/2019200feb/201950300%
jun/191000apr/2019200400%
1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @gluizqueiroz ,

 

I'm assuming you have a calendar table, you need to also have a endo of month column on the sales and on the calendar table (this is because I don't know how you have your model setup)

 

Create the following measure:

Previous = 
VAR Date_Selection =
    CALCULATE (
        MAX ( Sales[EndofMonth] );
        FILTER (
            ALLSELECTED ( 'Calendar' );
            'Calendar'[EndOfMonth] < MAX ( 'Calendar'[EndOfMonth] )
        )
    )
RETURN
  IFERROR (
        (
            SUM ( Sales[Sales] )
                - CALCULATE (
                    SUM ( Sales[Sales] );
                    FILTER ( ALL ( 'Calendar'[EndOfMonth] ); 'Calendar'[EndOfMonth] = Date_Selection )
                )
        )
            / CALCULATE (
                SUM ( Sales[Sales] );
                FILTER ( ALL ( 'Calendar'[EndOfMonth] ); 'Calendar'[EndOfMonth] = Date_Selection )
            );
        0
    )

Check PBIX file attach.

 

Regards,

MFelix

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

3 REPLIES 3
MFelix
Super User
Super User

Hi @gluizqueiroz ,

 

I'm assuming you have a calendar table, you need to also have a endo of month column on the sales and on the calendar table (this is because I don't know how you have your model setup)

 

Create the following measure:

Previous = 
VAR Date_Selection =
    CALCULATE (
        MAX ( Sales[EndofMonth] );
        FILTER (
            ALLSELECTED ( 'Calendar' );
            'Calendar'[EndOfMonth] < MAX ( 'Calendar'[EndOfMonth] )
        )
    )
RETURN
  IFERROR (
        (
            SUM ( Sales[Sales] )
                - CALCULATE (
                    SUM ( Sales[Sales] );
                    FILTER ( ALL ( 'Calendar'[EndOfMonth] ); 'Calendar'[EndOfMonth] = Date_Selection )
                )
        )
            / CALCULATE (
                SUM ( Sales[Sales] );
                FILTER ( ALL ( 'Calendar'[EndOfMonth] ); 'Calendar'[EndOfMonth] = Date_Selection )
            );
        0
    )

Check PBIX file attach.

 

Regards,

MFelix

 

 


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hey @MFelix.

Thanks for helping me Mr. Felix! 
I adapt your solution to my case and it works nice!
I didn't need to use End Of Month, because I can't. I have year, quarter and month in my matrix and it create a drill, so I need to make this dynamic and your solution guide me to achieve my goal.

Thanks thanks! 

Hi @gluizqueiroz ,

 

Glad I could help, since you didn't refer anything I just did a simple table as you add in your example.

 

No need for the Mr. :):)

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.