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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
kevinko14
Regular Visitor

Calculate variance from previous date

Hi,

 

I have a table as below, so I would like to find out the production variance between 2 different reportdate. How can I do this in Power BI?

 

kevinko14_0-1637306232937.png

 

I created pivot table as example

kevinko14_1-1637306273067.png

 

I would like the end reuslt is like below.

Example:

Variance between reportdate 25/10/2021 and 26/10/2021 is 22-6=16

then variance between reportdate 26/10/2021 and 27/10/2021 is 23-22=1

kevinko14_2-1637306298922.png

 

This is what I created in PowerBI.

kevinko14_3-1637306334783.png

 

Thank you so much for your help.

 

Regards,

Kevin

 

1 ACCEPTED SOLUTION
v-xiaotang
Community Support
Community Support

Hi @kevinko14 

Based on this example, the solution is 

vxiaotang_0-1637654886499.png

create the measures,

Measure = 
    var _predate=CALCULATE(MAX('Table'[ReportDate]),FILTER(ALL('Table'),'Table'[ReportDate]<MAX('Table'[ReportDate])))
    var _prevalue=CALCULATE(SUM('Table'[Production]),FILTER(ALL('Table'),'Table'[ReportDate]=_predate&&'Table'[Date]=MAX('Table'[Date])))
return IF(ISBLANK(_predate),0,SUM('Table'[Production])-_prevalue)

result

vxiaotang_1-1637654967446.png

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-xiaotang
Community Support
Community Support

Hi @kevinko14 

Based on this example, the solution is 

vxiaotang_0-1637654886499.png

create the measures,

Measure = 
    var _predate=CALCULATE(MAX('Table'[ReportDate]),FILTER(ALL('Table'),'Table'[ReportDate]<MAX('Table'[ReportDate])))
    var _prevalue=CALCULATE(SUM('Table'[Production]),FILTER(ALL('Table'),'Table'[ReportDate]=_predate&&'Table'[Date]=MAX('Table'[Date])))
return IF(ISBLANK(_predate),0,SUM('Table'[Production])-_prevalue)

result

vxiaotang_1-1637654967446.png

 

Best Regards,

Community Support Team _Tang

If this post helps, please consider Accept it as the solution to help the other members find it more quickly.

@v-xiaotang It works, thank you so much.

amitchandak
Super User
Super User

@kevinko14 , refer if this can help

 

How to use two Date/Period slicers :https://www.youtube.com/watch?v=WSeZr_-MiTg

 

Day Intelligence - Last day, last non continous day
https://medium.com/@amitchandak.1978/power-bi-day-intelligence-questions-time-intelligence-5-5-5c324...

@amitchandak 

Thanks for your video. Sorry that I confused you, I would like to find out variance of production from two different dates 

for example:

 

Cell B19 is variance between 25/10/2021 and 26/10/2021, formula B6-B5=22-6=16

Cell B20 is variance between 26/10/2021 and 27/10/2021, formula B7-B6=23-22=1

 

How can I do this in powerbi?

kevinko14_0-1637314136742.png

 

Thank you so much.

 

Kevin

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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