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
srkase
Helper IV
Helper IV

ORDER BY ASC OR DESC REQUIRED FOR A CALCULATION

Hi

 

The below is one of my dax .. I am calculating YOY growth in the calculation...

 

I always wanted to sort my results based on current year YOY%... 

 

YoYVal% =
VAR _currentyearvalue = [totval]
VAR _currentyear =
    MAX ( PROD_CABLE[YEAR] )
VAR _previousyear =
    MAXX ( FILTER ( ALL ( 'PROD_CABLE' ), 'PROD_CABLE'[YEAR] < _currentyear ), 'PROD_CABLE'[YEAR] )
VAR _previousyearvalue =
    CALCULATE ( [totval], 'PROD_CABLE'[YEAR] = _previousyear )
RETURN
    IF (
        _previousyearvalue && _currentyearvalue
            && HASONEVALUE ( 'PROD_CABLE'[YEAR] ),
        DIVIDE ( _currentyearvalue - _previousyearvalue, _previousyearvalue )
    )
 
how to add the sort option...
thanks in advance
 
Regards
SRK
1 REPLY 1
amitchandak
Super User
Super User

@srkase , In power bi, You have to add a sort in visual. Not in measure unless you are creating rank or TOPn

 

also for YOY try measure like below with help from date table

 

//Only year vs Year, not a level below

 

This Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])))
Last Year = CALCULATE(sum('Table'[Qty]),filter(ALL('Date'),'Date'[Year]=max('Date'[Year])-1))
diff = [This Year]-[Last Year ]
diff % = divide([This Year]-[Last Year ],[Last Year ])

 

or you can have

Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),dateadd('Date'[Date],-1,Year))
Year behind Sales = CALCULATE(SUM(Sales[Sales Amount]),SAMEPERIODLASTYEAR('Date'[Date]))

 

The information you have provided is not making the problem clear to me. Can you please explain with an example.

Appreciate your Kudos.

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.