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

Try your skills in the Power BI Dataviz World Championship! Round one ends June 26. Join now

Reply
jiglow3501
Frequent Visitor

Difference between two columns or rows

YearTotal SalesDifference in Sales from Last Year (should be result
20140 
20152.52.5
20164.52
201794.5
20180-9
201922

 

Find the difference within same column using DAX (result should be third column)

1 ACCEPTED SOLUTION

Rank = RANKX(flu,flu[Year],,ASC,Dense)

 

difference Ly = LOOKUPVALUE(flu[Total Flu Patients],flu[Rank],flu[Rank]) 

                              - LOOKUPVALUE(flu[Total Flu Patients],flu[Rank],flu[Rank] - 1)

 

with second dax formula 

 

i get message stating "table of multiple values was supplied where single value was expected"

 

I am calculating based on single year and i do not have date column or anyfurther drilldown on year.

 

your help is greatly appreciated. 

View solution in original post

4 REPLIES 4
jiglow3501
Frequent Visitor

Year    T otal Sales       Difference in Sales from Last Year (should be result)
2014    0
2015   2.5                          2.5
2016   4.5                           2
2017   9                             4.5
2018   0                             -9
2019   2                               2

 

How do you write dax for it? 

@jiglow3501,

 

You could try something like:

 

Rank = RANKX(Table1,Table1[Year],,ASC,Dense) 

then 

 

Diff in Sales LY = 
LOOKUPVALUE ( Table1[Total Sales], Table1[Rank], Table1[Rank] )
    - LOOKUPVALUE ( Table1[Total Sales], Table1[Rank], Table1[Rank] - 1 )





Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

Proud to be a Super User!



Rank = RANKX(flu,flu[Year],,ASC,Dense)

 

difference Ly = LOOKUPVALUE(flu[Total Flu Patients],flu[Rank],flu[Rank]) 

                              - LOOKUPVALUE(flu[Total Flu Patients],flu[Rank],flu[Rank] - 1)

 

with second dax formula 

 

i get message stating "table of multiple values was supplied where single value was expected"

 

I am calculating based on single year and i do not have date column or anyfurther drilldown on year.

 

your help is greatly appreciated. 

v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @jiglow3501,

 

For calculated column:

Difference in Sales from Last Year =
VAR previousYearTotal =
    CALCULATE (
        LASTNONBLANK ( Table5[Total Sales], 1 ),
        FILTER ( Table5, Table5[Year] = EARLIER ( Table5[Year] ) - 1 )
    )
RETURN
    Table5[Total Sales] - previousYearTotal

For a measure displayed in a visual:

Difference in Sales from Last Year measure =
MAX ( Table5[Total Sales] )
    - CALCULATE (
        MAX ( Table5[Total Sales] ),
        FILTER ( ALLSELECTED ( Table5 ), Table5[Year] = MAX ( Table5[Year] ) - 1 )
    )

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Fabric Data Days is here Carousel

Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.