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

Need help with writing DAX for specific problem

Hi all,

How could I achieve below requirement.

PY --> Previous Year (based on year selection in slicer)
TY --> This Year  (based on year selection in slicer)

Below you can find the pbix file.

https://drive.google.com/open?id=1kCtpjmQubCnOsGSU2Kf1PyLej5GrtnDq

 

 

LifecycleIntroduction...Growth...Maturity...
 PYTYDeltaDelta %PYTYDeltaDelta %PYTYDeltaDelta %
QTYS            
Price            
Revenue            
Growth Ratio [Rev.]            

 

 

Thanks,
AS

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @Anonymous ,

 

Create two tables:

 

Calculation              ID

Price 1
Quantity 2
Revenue 3
Growth Ratio [Rev]

4

 

Time       ID

TY 1
PY 2
Delta 3
Delta % 4

 

Add the following measure:

Measure =
VAR CY =
    FILTER ( ALL ( 'Calendar'[Year] ); 'Calendar'[Year] = MAX ( 'Calendar'[Year] ) )
VAR PY =
    FILTER (
        ALL ( 'Calendar'[Year] );
        'Calendar'[Year]
            = MAX ( 'Calendar'[Year] ) - 1
    )
VAR Price_TY =
    CALCULATE ( [Price]; CY )
VAR Price_PY =
    CALCULATE ( [Price]; PY )
VAR Quantity_TY =
    CALCULATE ( [Quantity]; CY )
VAR Quantity_PY =
    CALCULATE ( [Quantity]; PY )
VAR Revenue_TY =
    CALCULATE ( [Revenue]; CY )
VAR Revenue_PY =
    CALCULATE ( [Revenue]; PY )
RETURN
    SWITCH (
        TRUE ();
        MAX ( 'Calculations'[Calculation] ) = "Price"
            && MAX ( TimeTable[Time] ) = "TY"; Price_TY;
        MAX ( 'Calculations'[Calculation] ) = "Price"
            && MAX ( TimeTable[Time] ) = "PY"; Price_PY;
        MAX ( 'Calculations'[Calculation] ) = "Price"
            && MAX ( TimeTable[Time] ) = "Delta"; Price_TY - Price_PY;
        MAX ( 'Calculations'[Calculation] ) = "Price"
            && MAX ( TimeTable[Time] ) = "Delta %"; FORMAT ( DIVIDE ( ( Price_TY - Price_PY ); Price_PY ); "#,00%" );
        MAX ( 'Calculations'[Calculation] ) = "Quantity"
            && MAX ( TimeTable[Time] ) = "TY"; Quantity_TY;
        MAX ( 'Calculations'[Calculation] ) = "Quantity"
            && MAX ( TimeTable[Time] ) = "PY"; Quantity_PY;
        MAX ( 'Calculations'[Calculation] ) = "Quantity"
            && MAX ( TimeTable[Time] ) = "Delta"; Quantity_TY - Quantity_PY;
        MAX ( 'Calculations'[Calculation] ) = "Quantity"
            && MAX ( TimeTable[Time] ) = "Delta %"; FORMAT ( DIVIDE ( ( Quantity_TY - Quantity_PY ); Quantity_PY ); "#,00%" );
        MAX ( 'Calculations'[Calculation] ) = "Revenue"
            && MAX ( TimeTable[Time] ) = "TY"; Revenue_TY;
        MAX ( 'Calculations'[Calculation] ) = "Revenue"
            && MAX ( TimeTable[Time] ) = "PY"; Revenue_PY;
        MAX ( 'Calculations'[Calculation] ) = "Revenue"
            && MAX ( TimeTable[Time] ) = "Delta"; Revenue_TY - Revenue_PY;
        MAX ( 'Calculations'[Calculation] ) = "Revenue"
            && MAX ( TimeTable[Time] ) = "Delta %"; FORMAT ( DIVIDE ( ( Revenue_TY - Revenue_PY ); Revenue_PY ); "#,00%" );
        BLANK ()
    )

 

Now make a matrix with the following setup:

  • Rows: Calculation
  • Columns: Lifecicle / Time
  • Values: Measure

Drill down the matrix to the last level and add a slicer for year.

 

You need to add to the measure the calculation for revenue growth since I'm not sure how you want to calculate.

 

Check PBIX file with the result.

 

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 @Anonymous ,

 

Create two tables:

 

Calculation              ID

Price 1
Quantity 2
Revenue 3
Growth Ratio [Rev]

4

 

Time       ID

TY 1
PY 2
Delta 3
Delta % 4

 

Add the following measure:

Measure =
VAR CY =
    FILTER ( ALL ( 'Calendar'[Year] ); 'Calendar'[Year] = MAX ( 'Calendar'[Year] ) )
VAR PY =
    FILTER (
        ALL ( 'Calendar'[Year] );
        'Calendar'[Year]
            = MAX ( 'Calendar'[Year] ) - 1
    )
VAR Price_TY =
    CALCULATE ( [Price]; CY )
VAR Price_PY =
    CALCULATE ( [Price]; PY )
VAR Quantity_TY =
    CALCULATE ( [Quantity]; CY )
VAR Quantity_PY =
    CALCULATE ( [Quantity]; PY )
VAR Revenue_TY =
    CALCULATE ( [Revenue]; CY )
VAR Revenue_PY =
    CALCULATE ( [Revenue]; PY )
RETURN
    SWITCH (
        TRUE ();
        MAX ( 'Calculations'[Calculation] ) = "Price"
            && MAX ( TimeTable[Time] ) = "TY"; Price_TY;
        MAX ( 'Calculations'[Calculation] ) = "Price"
            && MAX ( TimeTable[Time] ) = "PY"; Price_PY;
        MAX ( 'Calculations'[Calculation] ) = "Price"
            && MAX ( TimeTable[Time] ) = "Delta"; Price_TY - Price_PY;
        MAX ( 'Calculations'[Calculation] ) = "Price"
            && MAX ( TimeTable[Time] ) = "Delta %"; FORMAT ( DIVIDE ( ( Price_TY - Price_PY ); Price_PY ); "#,00%" );
        MAX ( 'Calculations'[Calculation] ) = "Quantity"
            && MAX ( TimeTable[Time] ) = "TY"; Quantity_TY;
        MAX ( 'Calculations'[Calculation] ) = "Quantity"
            && MAX ( TimeTable[Time] ) = "PY"; Quantity_PY;
        MAX ( 'Calculations'[Calculation] ) = "Quantity"
            && MAX ( TimeTable[Time] ) = "Delta"; Quantity_TY - Quantity_PY;
        MAX ( 'Calculations'[Calculation] ) = "Quantity"
            && MAX ( TimeTable[Time] ) = "Delta %"; FORMAT ( DIVIDE ( ( Quantity_TY - Quantity_PY ); Quantity_PY ); "#,00%" );
        MAX ( 'Calculations'[Calculation] ) = "Revenue"
            && MAX ( TimeTable[Time] ) = "TY"; Revenue_TY;
        MAX ( 'Calculations'[Calculation] ) = "Revenue"
            && MAX ( TimeTable[Time] ) = "PY"; Revenue_PY;
        MAX ( 'Calculations'[Calculation] ) = "Revenue"
            && MAX ( TimeTable[Time] ) = "Delta"; Revenue_TY - Revenue_PY;
        MAX ( 'Calculations'[Calculation] ) = "Revenue"
            && MAX ( TimeTable[Time] ) = "Delta %"; FORMAT ( DIVIDE ( ( Revenue_TY - Revenue_PY ); Revenue_PY ); "#,00%" );
        BLANK ()
    )

 

Now make a matrix with the following setup:

  • Rows: Calculation
  • Columns: Lifecicle / Time
  • Values: Measure

Drill down the matrix to the last level and add a slicer for year.

 

You need to add to the measure the calculation for revenue growth since I'm not sure how you want to calculate.

 

Check PBIX file with the result.

 

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



Anonymous
Not applicable

Hey @MFelix ,

Thanks That's what I was looking for. I also started in the same way but couldn't figure out how to use them all in one measure. Revenue growth is the same ratio of this year to last year. But it's already covered with Delta%.

Again, thanks a ton for the quick help.

Have a nice Christmas time and happy holidays.

Greg_Deckler
Super User
Super User

See if my Time Intelligence the Hard Way provides a method of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.