Distribute yearly measure over months with predefired percent values - powerbi

I have a yearly goal for number of graduates. I want to distribute this yearly number to monthly level using predefined percent numbers.
I would like to get
jan = 1.7% * 292 = 4.96
feb = 1.4% * 292 = 4.01
etc...
The problem is that yearly number of graduates has date of 2021-01-01 and relation to date table, so it will only work for the first month. (Other months are blank). I cannot change the date relation because I have other goals in the same table that use month
Here are my measures
Graduates goal = CALCULATE( SUM(value), Measure = 'Graduates goal')
Goal% = CALCULATE( SUM(value), Measure = 'Graduates%)
Montly graduate target = CALCULATE( [Graduates goal] * [Goal%])
I have tried using ALL(Dates[Month]) ALL(Dates[Year]) but I cannot get past that month level restriction in yearly goal.

Update:
I was able to solve this with crossfilter something like this
Montly graduate target = CALCULATE([Graduates goal], CROSSFILTER( Goals, Dates, None), YEAR(Pvm) = YEAR(TODAY())) * Goal%

Related

DAX Rolling Average Applying at Year Level, But Not Month Level

I am trying to get a rolling 3/6/12 month average of revenue by month using DAX in a SSAS Tabular model. There is a date table in my model and I have created inactive links between my fact table and my date table for each date in the fact (Date of Service, Invoice Date, etc.). I have created a measure that uses USERELATIONSHIP to activate the specific link I need.
Revenue by DOS:=
CALCULATE( [Total Gross Revenue],
USERELATIONSHIP(D_DATE[W_DT_ID],Fact_Charge[W_SERVICE_DT_ID])
)
Here is the code I am using to create the rolling average, which I copied from a SQLBI video on the same subject:
Net Revenue R3M:=
VAR NumOfMonths = 3
VAR LastSelectedDate = MAX(D_DATE[Calendar_Date])
VAR Period =
DATESINPERIOD( D_DATE[Calendar_Date], LastSelectedDate, -NumOfMonths, MONTH)
VAR Result =
CALCULATE(
AVERAGEX(
VALUES(D_DATE[Month Year]),
[Revenue by DOS]
),
Period
)
Return
Result
For some reason when I deploy the model and try to use it in Power BI, it runs this rolling average at the year level, but not the month. For instance, the Power BI matrix visual will show the year 2021 and will have a value that is equal to the average of the last 3 months of 2021, but the individual months show the same value that is contained in the Revenue by DOS measure itself.
Snip From Power BI
The goal is to have each individual month in the Revenue R3M column to be the 3 month average of the Revenue by DOS column.

DAX: Monthly AVG

I am looking for the "best practice" when it comes to calculating Monthly Averages in DAX. Ideally, I would like to use some of the DAX built in Time Intelligence Functions.
I have a measure called "Total Units". Total Units = COUNT(Table[UnitId])
Each row in my table represents when a single unit was sold.
When I put my Total Units and Sales Date into a bar chart, I can see how many units were sold every month.
How do I now calculate the monthly average?
Month Total Units (Sold)
Jan 2019 10
Feb 2019 30
I want a measure that will tell me that the Monthly AVG is (10+30)/2 = 20
There are a couple of ways to solve this. Assuming you have a [Month] column on your table, you could simply do:
MonthlyAvg = DIVIDE ( [Total Units] , DISTINCTCOUNT( 'Table'[Month] ) )
In other words, simply dividing the total with the number of months considered.
If you have a more "proper" data model, with a separate calendar dimension, you should do something like:
MonthlyAvg = AVERAGEX( VALUES( 'Calendar'[Month] ) , [Total Units] )
All you need is a simple average measure as below,
Total Avg = AVERAGE(Total Units (Sold))
When you select any period for date, measure will adjust and provide the average for the selection.
Let's say you select for year 2019 and Months are Jan, Feb, March
(Jan + Feb + March)/3
Hope it helps!!

Monthly sales trend in Power BI based on working days

I have daily sales data and I would like to create a measure or a column that calculates the monthly sales trend based on the average daily units sold in the month.
For example, as of 08/17/2017, we have had 12 working days this month and 360 units sold. This is an average of 30 units per day. So to calculate the trend manually, I would take 30 units/day and multiply it by the 23 total working days in the month for a trend of 690 units sold.
Here is some sample data.
EDIT: Adjusted the explanation and measure definitions based on the new info that was added to the post
You can create three measures to help you reaching your final result. In this example I'm merely splitting the measure into three parts to increase the readability. You can put it all together in a single measure if you like.
The first measure gives you the number of units sold. This is just a simple sum of units sold, since you have already added a month filter to your measures in your sample:
Sales:=SUM('SalesTable'[Items Sold])
The second measure gives you the number of working days for the filtered month up until the latest entry in your Sales Table:
WorkingDaysToDate:=
CALCULATE(
COUNTROWS('DateTable'),
FILTER(
'DateTable',
'DateTable'[Date] > CALCULATE(MAX('SalesTable'[Date]))
&& [Type] = 'Work Day'
)
)
The third measure gives you the total number of working days for the filtered month:
WorkingDays:=
CALCULATE(
COUNTROWS('DateTable'),
FILTER(
'DateTable',
[Type] = 'Work Day'
)
)
In the end you can combine the three measures to get your month trend:
MonthTrend:=DIVIDE([Sales], [WorkingDaysToDate]) * [WorkingDays]
Total Month To Date Sales
TotalMTDSales = SUM('Sales Table'[Items Sold])
Total Month To Date Work Days
TotalMTDWorkDays = CALCULATE(
COUNT('DateTable'[Date]),
FILTER(ALLSELECTED('DateTable'), 'DateTable'[Date]<=MAX('SalesTable'[Date]) &&
'DateTable'[Type] = "Work Day"))
Total Work Days
TotalWorkDays = CALCULATE(
COUNTROWS('DateTable'),
FILTER(
'DateTable',
'DateTable'[Type]= "Work Day"))
Trend = ([TotalMTDSales] / [TotalMTDWorkDays] ) * [TotalWorkDays]
Filter by Month

PowerBI - Measure to Summarize Daily data into Monthly Counts

I have a table of defect data that I would like to create a MEASURE that gives me a count of defects for each month. I know I need to use a date table but my attempts thus far haven't worked out.
What I am looking for when this works is a simple count by month:
January 125
February 225
March 220
April 120
Defect Table
Date Table
Here is the Measure I was trying to build without any luck...
Monthly Defects =
// TOTALYTD(COUNT(Defects[Defect]), 'Date'[Date])
VAR defectDate = FIRSTDATE(Defects[Created Date])
VAR defectYear = YEAR(defectDate)
VAR defectMonth = MONTH(defectDate)
RETURN
CALCULATE (
COUNT(Defects[Defect]),
FILTER (
Defects,
Defects[Created Date] <= defectDate &&
(YEAR (Defects[Created Date]) = defectYear) && (MONTH(Defects[Created Date]) = defectMonth)
)
)
Here is what I am looking to do in the end.
If you simply want a count per month, then your measure should be
Monthly Defects=COUNTROWS(Defects)
This is assuming that you have a relationship between your defect table and your date table.

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).