Forum Discussion
Calculate variance based on previous month value
Hello All,
New to Power BI and looking forward for some guidance.
I have 7 columns and i need to calculate variance at aggreaget level of Code and Account compared to previous month based on amt.
Period is month and Year = year.
I need to get the variance 0.054 for this sample set.
Regards,
Chandrakanth.K
6 Replies
- amitchandak
Super User
Chandrash12 , Create a date using year and month and then join it with a date table having year and month
Date = Date([year],[month],1)
Calendar = Addcolumns(calendar(date(2020,01,01), date(2021,12,31) ), "Month no" , month([date])
, "Year", year([date])
, "Month Year", format([date],"mmm-yyyy")
, "Month year sort", year([date])*100 + month([date])
, "Qtr Year", format([date],"yyyy-\QQ")
, "Qtr", quarter([date])
, "Month",FORMAT([Date],"mmmm")
, "Month sort", month([DAte])
, "Is Today" ,if([Date]=TODAY(),"Today",[Date]&"")
, "Month Type", Switch( True(),
eomonth([Date],0) = eomonth(Today(),-1),"Last Month" ,
eomonth([Date],0)= eomonth(Today(),0),"This Month" ,
Format([Date],"MMM-YYYY") )
,"Year Type" , Switch( True(),
year([Date])= year(Today()),"This Year" ,
year([Date])= year(Today())-1,"Last Year" ,
Format([Date],"YYYY")
)
)Then create measures like these and take diff for variance.
Use table from date table in visual slicer
MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))
last month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth('Date'[Date]))diff = [MTD Sales]-[last MTD Sales]
diff % = divide([MTD Sales]-[last MTD Sales],[last MTD Sales])Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKAWhy Time Intelligence Fails - Powerbi 5 Savior Steps for TI :https://youtu.be/OBf0rjpp5Hw
https://amitchandak.medium.com/power-bi-5-key-points-to-make-time-intelligence-successful-bd52912a5bd4
To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.- Chandrash12Frequent Visitor
Thank you Amit for your response. I tried and i am getting this below errors when i tried to create new column/measure.
- Chandrash12Frequent Visitor
Need help
- AnonymousNot applicable
HI Chandrash12,
That is a calculated table expression, you can't use it in other types of calculated fields. Please create a new calculated table to use these formulas.
Regards,
Xiaoxin Sheng
- Chandrash12Frequent Visitor
Hello Xiaoxin Sheng,
Thank you for your response. I understood and create table first and tried to use this DAX in add custom column but i get two error
1.
and 2