YTD Average in DAX - powerbi

Need to calculate YTD Average and LYTD Average in DAX , Our Fiscal year starts from Apr.
So if my current day is 5th of the June 2017 then lytd_AVG would be from Apr to June would be
(MTD Aprn 17) + (MTD May 17) + (MTD June 17)/3
and LYTD_AVG would be
(MTD Apr 16) + (MTD May 16) + (MTD June 16)/3
Assuming my current date is 06-03-2017, the YTD avg would be 60

Assuming your data is given monthly (since you have no sample data), for YTD you should be able to use something that looks like this:
YTD Avg = CALCULATE(AVERAGE(Table[Value]), DATESYTD(Table[Date], "03-31"))
The last argument specifies the year-end date (Reference).
You can use the SAMEPERIOODLASTYEAR function for LYTD:
LYTD Avg = CALCULATE(AVERAGE(Table[Value]),
SAMEPERIODLASTYEAR(DATESYTD(Table[Date], "03-31")))
Edit: Since your data is daily, we need to do a bit more work.
First, add month and year calculated columns to your table:
Month = MONTH(Table[Date])
FiscalYear = YEAR(MINX(DATESYTD(Table[Date], "03-31"), [Date]))
Then you will group by months in your measures:
YTD = AVERAGEX
SUMMARIZE(Table1,
Table1[Month],
"MTDAmount", SUM(Table1[Amount])),
[MTDAmount])
LYTD = AVERAGEX(
SUMMARIZE(
FILTER(ALL(Table1),
Table1[Month] IN VALUES(Table1[Month]) &&
Table1[FiscalYear] = MAX(Table1[FiscalYear]) - 1),
Table1[Month],
"MTDAmount", SUM(Table1[Amount])),
[MTDAmount])
You should then be able to build tables like this:

Related

How to add previous month value with current month revenue and show in current month in Power BI

I have data on Customer wise revenue by month
Output requires:-
where January month data is the new value and after that next month is the calculation of current month value plus just previous month value
i.e. Feb 2020 value = Current Feb month value + Previous month Jan value
How to do the above calculation in Power BI?
Use the following measure:
YTD=
VAR date = SELECTEDVALUE(table[date])
RETURN CALCULATE( SUM(table[value],
ALL(table[date]),
table[date] <= date)

Partial data for year over year comparison handling on DAX

I have the following tables:
Revenue
Branch
Date
I have a table viz with branch name, % over last year for revenue
Here, my calculations are correct and numbers are correct as per requirement.
DAX I am using:
% over Last Year = IFERROR(
([Revenue 2019 YTD] / [Total Revenue 2018 for YTD]) -1,
BLANK())
Problem:
For 3 branches, these branches were acquired mid-year on 2018 and only has data from July of 2018.
When I am calculating data for % over last year, the numbers are incorrect for these branches as they only had partial data on 2018 and complete data ( Jan to current month) in 2019.
I need help on how I can calculate the % over last year also while considering the min date of 2018 for some branches that were acquired mid-year in 2018.
The solution to my question:
This Year YTD branch Growth with Partial Data =
var _thisyear = YEAR([Today])
var _currentweek = WEEKNUM([Today])
// last year min date
var _minweek =
CALCULATE(
SUMMARIZE(
Revenue,
"Min Date lY", CALCULATE(MIN(Revenue[weeknum])))
, FILTER(WeekCalendar, WeekCalendar[CalendarYear] = _thisyear - 1
))
return
SUMx(
SUMMARIZE(Revenue,
Revenue[Weekkey],
"Revenue YTD",
CALCULATE(
SUM(Revenue[Revenue]),
FILTER(Revenue, Revenue[weeknum] <= _currentweek),
FILTER(Revenue, Revenue[Year] = _thisyear),
FILTER(Revenue, Revenue[weeknum] >= _minweek), GROUPBY(branch, branch[Branchname])
)
),
[Revenue YTD]
)
If anyone has any suggestions to my DAX, Please let me know as well.

POWER BI - Create a measure to compare Forecast vs Sales

Create a measure to compare forecast vs sales in power BI.
The logic is that at the beginning of Jan. 2018 it is forecasted the sales for the whole year and the amount of pcs sold in Jan. 2018 is only known in Feb. 2018 (next month's file). As an example, we are in Nov. 2018 and it is known how many pcs were sold in the previous months. I want to create a table to compare forecast vs sales.
My dataset looks like the figure below. It is marked in red the historical data.
An example of a power BI matrix that I am trying to create by dividing forecast by sales
It looks like you need to normalize your data source. This may look something like:
Now you can create some measures. Create a Forecast Qty measure:
Forecast Qty:=CALCULATE (
SUM ( SourceTable[Qty] ),
SourceTable[Type] = "Forecast"
)
A Sold Qty measure:
Sold Qty:=CALCULATE (
SUM ( SourceTable[Qty] ),
SourceTable[Type] = "Sold"
)
And a Sales % Forecast Measure:
Sales % Forecast:=DIVIDE (
[Sold Qty],
[Forecast Qty],
BLANK()
)
Now you can lay out your visualisation as you choose. For example:

Rolling 3 months DAX

I have had a headache since yesterday with a measure.
My table is Data and in this table, I have a column Data[Date] which contains the first day of each month from January to June and a measure which calculates Total revenue.
I need a measure that calculates for June: Total REV = April + May + June.
I have tried this measure:
CALCULATE([TOTAL REV], DATESINPERIOD(Data[Date], LASTDATE(Data[Date]), -3, MONTH))
but in order to have the correct number I need to select all three months in the slicer, not just the month I am interested in.
When you've got just one date selected in the slicer the filter context for the CALCULATE is just that month.
So I suspect that something similar to the below would fix your issue as it would allow the CALCULATE to consider the whole date table:
CALCULATE([TOTAL REV], DATESINPERIOD( ALL(Data[Date]), LASTDATE(Data[Date]), -3, MONTH))
Try this:
sumx(DATESINPERIOD('Data'[Date], LASTDATE('Data'[Date]), -3, MONTH) , [TOTAL REV])

Calculate annual total from monthly total using Measure in Power BI

I want to calculate annual revenue for each month from monthly revenue data. Sample data is shown as below:
e.g. For annual revenue of 2015 May = sum of monthly revenue from 2015 Jan to 2015 May, and so on.
The problem is, the Monthly Revenue is a measure. I want to create a measure for Annual Revenue as well, so that it can interact with other filters. However, I only know how to write the expression using Calculated Column:
Annual Revenue =
CALCULATE(
[Monthly Revenue],
FILTER(
'Month',
'Month'[Year] = EARLIER('Month'[Year]) &&
'Month'[MonthKey] <= EARLIER('Month'[MonthKey])
)
)
How can I translate the above expression so that it will work with Measure?
It sounds like what you want is a YTD measure for any given date (i.e. in May 2015, YTD is January-April 2015). I typically wouldn't do this using a [Monthly Revenue] measure and a Month table. I'd do this using a regular date table, a base Revenue measure, and DATESYTD.
However, using the MONTH table as you've outlined, this is what I'd do for a measure:
Annual Revenue Measure =
CALCULATE (
[Monthly Revenue],
FILTER (
ALL ( 'Month' ),
'Month'[Year] = MAX ( 'Month'[Year] )
&& 'Month'[MonthKey] <= MAX ( 'Month'[MonthKey] )
)
)
You'll note it's almost the same as you have for your calculated column, except using MAX rather than EARLIER (since EARLIER only applies to calculated columns).