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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
SuperSusa
Frequent Visitor

DAX - EARLIER - % change one cell down

Hi,

 

I am new to PowerBi and this is my first time posting here. What a fantastic forum! Thank you all for your time and sharing your knowledge, you really help people out there a lot!

 

I would like to generate % change from the actual month to the previous months and have therefore created two  index columns with Power Query and then used the EARLIER command. 

 

Then I found two wys of calculating % change but the problem is the same, the results should be down by one line. Changepercent.PNG

Here is the second formula: 

Changepercent2.PNG

In the forum it seems like there are possibilities to copy the table and then merge with PowerQuery, but in this case it is the position of the DAX output that is causing me trouble. 

 

Any suggestions are very much appreciated, thank you!

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

@SuperSusa 
Like this

% Change =
VAR CurrentPrice = 'PQ_Bitumen'[Price]
VAR PreviousPrice =
    MAXX (
        FILTER ( 'PQ_Bitumen', 'PQ_Bitumen'[Index.1] = EARLIER ( 'PQ_Bitumen'[Index] ) ),
        'PQ_Bitumen'[Price]
    )
RETURN
    DIVIDE ( CurrentPrice - PreviousPrice, PreviousPrice )

View solution in original post

6 REPLIES 6
FreemanZ
Super User
Super User

hi @SuperSusa 

try like:

%Change =
VAR _pricepre =
MINX(
    FILTER(
        TableName, 
        TableName[Dato] = EDATE(EARLIER(TableName[Dato]), -1)
    ),
    [Price]
)
RETURN
DIVIDE([Price]-_pricepre, _pricepre)
tamerj1
Super User
Super User

@SuperSusa 
Like this

% Change =
VAR CurrentPrice = 'PQ_Bitumen'[Price]
VAR PreviousPrice =
    MAXX (
        FILTER ( 'PQ_Bitumen', 'PQ_Bitumen'[Index.1] = EARLIER ( 'PQ_Bitumen'[Index] ) ),
        'PQ_Bitumen'[Price]
    )
RETURN
    DIVIDE ( CurrentPrice - PreviousPrice, PreviousPrice )

@tamerj1 this worked perfectly, thank you so much , you saved my day or should I better say my whole week!:)

 

tamerj1
Super User
Super User

Hi @SuperSusa 
Just interchange between Index and Index.1 like

FILTER ( 'Table', 'Table'[Index.1] = EARLIER ( 'Table'[Index] ) ) 

this will retrieve the previous row. Then you can easily calculate the difference then the percentage.

Hi,

 

Thank you for your reply. 

I tried, and it comes close now, but thee values do still not come out right. Since the signs were negative, I converted to positive and vice versa via 0- in front of the equation. 

Changepercent3.PNG

@SuperSusa 

It should be

( CurrentRowPrice - PreviousRowPrice ) / PreviousRowPrice

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.