How to calculate Annual Variance on Monthly basis? - powerbi

Am new to Power BI and appreciate help on DAX for this requirement:
I have a FY slicer (July-June) in my Power BI reports and wants to show monthly trending across different FY years. Target data is structured like this in a table:
Dates | Target
30-06-2018 | 34000
30-07-2018 | 34000
30-08-2018 | 34000
********** | *****
30-06-2019 | 30000
30-07-2019 | 30000
********** | ******
I need to calculate annual variance with below formula to get monthly baseline for next year(2019), then calculate cumulative reduction variance across July-June:
('Target of 30-06-2018') - ('Target of 30-06-2019')/ 12
Dates are linked to another DATE table, which has Financial year and Financial month columns.
Thanks so much in advance for the help!!
Anita

You need to use the DAX PARALLELPERIOD
PARALLELPERIOD(<dates>,<number_of_intervals>,<interval>)
The documentation gives a perfect example:
= CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]), PARALLELPERIOD(DateTime[DateKey],-1,year))
So your calculation will something like:
= (
CALCULATE(SUM(TargetTable[Target])) -
CALCULATE(SUM(TargetTable[Target]), PARALLELPERIOD(Dates[Date],-1,year))
) / 12
If you want monthly variance, then you need to ensure that Dates[Date] is filtered at a grain to return a table of dates for the entire target month.
You can find a great blog on it here

For next year, I got June Baseline value with SAMPLEPERIODLASTYEAR.
1: Last year value = CALCULATE(SELECTEDVALUE (TargetTable[Target]),
SAMPLEPERIODLASTYEAR (Dates[Date]))
2: Base Target = IF (MONTH(SELECTEDVALUE(TargetTable[Dates])=6, DIVIDE ([Last year value]-SELECTEDVALUE (TargetTable[Target]), 12))
Still need to figure out Cumulative monthly variance across next financial year?

Related

Year over year running month total percentage change in power bi

I've been struggling with this for a while. I need to calculate running month total percentage change year over year. I got it working but its not getting the running total for the month to do the calculation. By the way this is on the graph. Here are my calculations below:
how graph looks
ImprovementIncidentPercentage = 1 - DIVIDE([CurrYearIncidents],[LastYearIncidents],0)
CurrYearIncidents = CALCULATE(count(VW_RI_INCIDENTONLY_PBI[Incident]),
Filter(VW_RI_INCIDENTONLY_PBI,VW_RI_INCIDENTONLY_PBI[EVENTDATE].[Year] =('newsecondyear'[SecondYearValue])))
LastYearIncidents = CALCULATE(count(VW_RI_INCIDENTONLY_PBI[Incident]),
Filter(VW_RI_INCIDENTONLY_PBI,VW_RI_INCIDENTONLY_PBI[EVENTDATE].[Year] = 'newfirstyear'[FirstYearValue]))
The second and first year value is used as slicers for them to be able to pick two years they want to see the percentage improvement on:
slicers to pick what two years to do percent improvement on
I know something has to change CurrYearIncidents and LastYearIncidents so it does the calculation for running total for the month not the monthly total. I am just not sure how to make it work. Here is the close look at the issue.
show as table graph of error
For January the calculation is correct 1-(10/14) = 28.6%
For February it should be 1-(30/29) but instead it does monthly total for february and doesn't add up january so it does 1-(20/15)
To get accumulation values month over month I use this measure:
Cumulative events = TOTALYTD ( count (VW_RI_INCIDENTONLY_PBI[INCIDENT]), VW_RI_INCIDENTONLY_PBI[EVENTDATE].[Date])
Please help!

Spilt Revenue By Percentages in right year buckets in Power BI

I have a list of product with revenues across 3 years. However I would like to split the revenue by 60 % and 40% for each year.
For instance:
Book -> 2020 -> 15mil
Book -> 2021 -> 18mil
Book -> 2022 -> 12mil
Therefore in Power BI the revenue should appear as:
2020 -> 60% x 15
2021 -> 40% x 15 + 60%*18
2022 -> 40% x 18 + 60% x 12
2023 -> 40% x 12
How can I code this in Power BI to ensure that the revenue are split accordingly?
Update:
I have tried to do a 60% and 40% split column and additional column of Year +1. How do I add them up on Power BI based on year?
I assumed some data model like the following:
[SalesAmt] = SUM(paid_price)
If we now create a table out of the year and [SalesAmt] we get the following. (My sales values were created for testing purposes)
Now for my understanding: You want to display the SalesAmt (which exact Measure doesn't matter) multiplied by 60% and add the SalesAmt from the previous year multiplied by 40%.
For this we can use the DAX formula SAMEPERIODLASTYEAR(), it takes one argument, the date-field for which you want to retrieve the last year's pendant.
[SalesAmt Buckets v1] =
SALES[SalesAmt] * 0.6
+ CALCULATE(SALES[SalesAmt], SAMEPERIODLASTYEAR(DATES[fq_date])) * 0.4
Explanation to this formula:
We calculate the current year's [SalesAmt] and multiply it by 60%, then we calculate [SalesAmt] and changing the filter context for this calculation by CALCULATE(). At the end we multiply by your 40% and return the result.
Notice how it is less for the firs year (2019), that's because we don't have a previous year for the row context year 2019, so we just retrieve the current year's value times 40%.
For the next years it's correct being 2020 = 40% * 79 + 60% * 95 = 85.

Calculate total variance in power bi with dax

I have 3 measures:
1) total_trx = SUM(mytable[trx])
2) trx_prev_month = CALCULATE([total_trx], DATEADD(calendar[date], -1,MONTH))
3) monthly_var = DIVIDE([total_trx],[trx_prev_month])-1
If I add a waterfall viz, x-axis with month, it gives me the % of monthly variation and a TOTAL bar at the end that sums all the variations.
I need to reproduce that total number in order to show a KPI as in "so far, we've increased ...%", changing when using a date slicer.
Seems like sum(monthly_var) is not allowed.
Any ideas?
Thank you very much.
Edit1: sample with date filter = Last 4 months
Jul 100 0%
Aug 110 10%
Sep 90 -20%
Oct 80 -10%
Total: -20% <- need a dax to calculate this number and show just -20%
Then if I change the filter to, for example LAST 6 MONTHS, I need to calculate it up to May
In order to get the desired result we will use an intermediate table in our query that will summarize the results by months:
use this code and replace calendar[Year Month] with your Year month column :
SUMX(
SUMMARIZECOLUMNS(calendar[Year Month],"Monthly_int_var",[monthly_var]),
[Monthly_int_var]
)

How to Calculate 3 Month Rolling Average with my current dataset in Power BI?

I'm new to power BI and i require your assistance. I want to create a visualisation showing the average number of tickets from the previous 3 months and compare it with the current month. Is there any easy way to do this?
I have tried many solutions online but it dosen't work. I think it is because my dataset may not suit the solution.
My data:
Tickets | Date
1 | 6/30/2019
1 | 6/10/2019
1 | 7/1/2019
0 | 7/2/2019
1 | 6/30/2019
There are many more columns and rows. The value of ticket is either 1 or 0 and the date can be repeated. This is the data i received from an API.
This is what i currently have
The data would get bigger and bigger as time goes by.
I would want to add a 3month rolling average line in this current visualization that i have.
Thank you!
Here we go:
First I created a column FirstDayMonth,this I use to group all data of the same month
FirstDayMonth = EOMONTH(Tickets[Date];-1)+1
My table looks like:
Next I create a summarized table grouped by the FirstDayMonth
TicketsMonth = SUMMARIZE(Tickets;Tickets[FirstDayMonth];"Amount"; SUM(Tickets[Tickets]))
I add a column Ave3PrevMonth
Ave3PrevMonth =
var totalMonths = YEAR(TicketsMonth[FirstDayMonth]) * 12 + MONTH(TicketsMonth[FirstDayMonth]) - 3
var periodStart = DATE(totalMonths/12;MOD(totalMonths;12);1)
var periodEnd = TicketsMonth[FirstDayMonth]
return
CALCULATE(SUM(TicketsMonth[Amount]);
FILTER(TicketsMonth; TicketsMonth[FirstDayMonth] >= periodStart && TicketsMonth[FirstDayMonth] < periodEnd))/3
This is the tricky bit as Power bi is not strong with dates..
I added an extra column PeriodStart to show the date from where average is taken:
PeriodStart =
var totalMonths = YEAR(TicketsMonth[FirstDayMonth]) * 12 + MONTH(TicketsMonth[FirstDayMonth]) - 3
return DATE(totalMonths/12;MOD(totalMonths;12);1)
End result:

Power BI Desktop Line Chart with Multiple Lines

I'm trying to overlay three different columns in one chart on Power BI Desktop.
To try to show a comparison of the number of orders per month by different years I have one column for Order Number, and three other columns for Sale Date; Sale Date 2016, Sale Date 2017 and Sale Date 2018. For each order number the three Sale Date columns have a number from 1-12 (representing the month in that year that the order occurred) or a null value (if the order occurred in another year). Something like this:
I'm trying to overlay the three Sale Date columns as individual lines on a line chart with Order Number (Count Distinct) as one axis and Sale Date 1-12 as the other axis. I would think that this would be comparatively simple but Power BI Desktop doesn't seem to have an option to set this up. I'd be open to other types of chart too, as long as the different years can be easily compared.
The reason you're having trouble is that your data is not shaped in a way that is conducive to the way Power BI works.
I'd recommend unpivoting your Sale 201x columns in the Query Editor before trying to do anything. When you do this, your data will look like this instead.
Order # | Year | Month
--------|-----------|------
101 | Sale 2016 | 6
102 | Sale 2017 | 8
103 | Sale 2018 | 12
104 | |
When it's in this format you can use it in a visual much more easily using Order # on your axis and Month for values while using Year as your legend.