I am shwoing a data of pressure in a graph by date which can selected from the filter ( days, months, years)
I would like to calculate the difference between the twos extremum data in the plot [ last Value- first Value] ( when user change a filter i show the new calculation as the graph will change )
here my custome expression but i not working properly ( Date is X axis values ) Level Pressure Y axis :
Abs(if([Property Name]="LevelPressure",[Average Reading])) - sum(if([Property Name]="LevelPressure",[Average Reading])) over (PreviousPeriod([Date]))
Related
I have a period of four years I am comparing. Each day the amount of positive and negative gains of sales is reflected in the data.
The raw data looks as such:
My dax calculation is:
Actions running total in From Start =
CALCULATE(
SUM('Total Data'[Actions]),
FILTER(
ALLSELECTED('Total Data'[From Start]),
ISONORAFTER('Total Data'[From Start], MAX('Total Data'[From Start]), DESC)
)
)
This is what my chart looks like:
But the chart should look more aligned as such:
The problem chart lies on a negative to a positive axis. Centered around a central important date. Each negative date is that many days before the date. Each positive date is reflected after the date of importance. This axis comes from the "From Start" Column in my raw data.
However, if the axis is positive, such as in the similar chart, the running total is just from the start of data.
Every time an entry of data does not display data (Example: The raw data for 4/2/2017 didn't have any values so it just doesn't exist) the chart displays a large total value. I need to find a way to reflect this data with a negative to a positive axis while evening the line out to look similar to the similar chart.
I'm guessing what's happening is that the second argument in your ISONORAFTER function is returning a blank value for terms that don't have data for that date and therefore treating it as if it were a zero (notice that the value is the same height as at zero).
To remedy this, let's remove any extra filter context other than the From Start value from the axis. This way it pulls in the date offset even if that particular Term doesn't have a value for it.
Actions running total in From Start =
VAR FromStart =
CALCULATE (
MAX ( 'Total Data'[From Start] ),
ALLEXCEPT ( 'Total Data', 'Total Data'[From Start] )
)
RETURN
CALCULATE (
SUM ( 'Total Data'[Actions] ),
FILTER (
ALLSELECTED ( 'Total Data'[From Start] ),
ISONORAFTER ( 'Total Data'[From Start], FromStart, DESC )
)
)
My Data is in weekly buckets. I want to split the number into a monthly number but, since there is an overlap in days falling in both the months, I want a weighted average of the data in terms of days that fall in each of the months. For example:
Now, in the above picture, I want to split that 200 (5/7*200 in Jan, 2/7 in Feb). How can I do that using Excel/ Power Pivot/ Dax Functions? Any help here is much appreciated.
Thank you!
Assuming your fact table looks something like below. Values are associated with the starting date of the week it occurred.
Although it may actually be a more granular data, having multiple rows for each week with additional attributes (such as identifiers of a person, a store, depending on the business), what being shown below will work the same.
What we need to do first is to create a date table. We can do that in "Design" tab, by clicking "Date Table", then "New".
In this date table, we need to add a column for starting date of the week which the date of each row is in. Set the cursor to "Add Column" area, and input following formula. Then rename this column to "Week Start Date".
= [Date] - [Day Of Week Number] + 1
Now, we can define the measure to calculate the number allocated to each month with following formula. What this measure is doing is:
Iterating over each row of the fact table
Count the number of days for the week visible in the filter context
Add the value portion for the visible days
Value Allocation := SUMX (
MyData,
VAR WeekStartDate = MyData[Week]
VAR NumDaysInSelection = COUNTROWS (
FILTER (
'Calendar',
'Calendar'[Week Start Date] = WeekStartDate
)
)
VAR AllocationRate = DIVIDE ( NumDaysInSelection, 7 )
RETURN AllocationRate * MyData[Value]
)
Result in the pivot table will be looking like this.
I have a list of projects from SharePoint which has one column for Start Date, and one column for End Date. I would like to create a Power BI visual which plots for all dates in a calendar how many projects are currently being worked on.
I have done something similar to this in SAS, and even Excel, where I can just have an arbitrary number of columns, representing a date, and then create an if statement referencing that date which gives a binary value for whether or not that date is in the desired interval. Then I can add those up and plot the totals against the aforementioned dates. As far as I have been able to do, I cannot replicate this in Power BI. Is there some sort of functionality or custom visual I do not know of which could achieve this?
You can do the following using the following 'pseudo' code.
First create a New Table from the modeling tab and use the following code to create a small calendar table.
Calendar =
CALENDAR (
MIN ( Projects[StartDate] ) ,
MAX ( Projects[EndDate] )
)
Create a measure from the same menu as where you created the table and add the following code
ActiveProjects =
var _selectedDate = MIN ('Calendar'[Date] )
RETURN
CALCULATE (
COUNTROWS ( Projects ) ,
ALL ( Projects ) ,
Projects[StartDate] < _selectedDate ,
Projects[EndDate] >= _selectedDate
)
Then plot the Date field from your calendar table against the measure you've just created and create an area chart for instance.
My question is that I'd like to calculate a daily average taking into account days with zeroes.
Let me clarify it:
I'd like to calculate the average daily value of units for each category, with the following table:
When I sum up the values for each day and category, I get:
I'd like to include in the average calculation the zeroes.
I use the following code:
SUMMARIZE(
Data,
Data[Category],
"Average",
AVERAGEX(
SUMMARIZE(
Data,
Data[Date],
"Sum of Units",
SUM(Data[Units])
),
[Sum of Units]
)
)
But the problem is that for category B it doesn't take into account those days with 0s.
Could you please guide me how to solve it?
Thanks in advance!
Jorge
One way to solve it would be to create a calendar table, which can then be used to count the number of days in any of your grouping periods. This also means you can use non standard calendars, for example something like a 4-4-5
With a calendar table created you can leverage the FIRSTDATE and LASTDATE functions in DAX.
I recommend adding a past dates column to the calendar table, which can be created using DAX with the following formula. The today function in DAX when used in a calculated column will only evaluate when the model is updated.
In my example I created a calculated column in the date table called Past_Dates
Past_dates =IF( TODAY() > [Date], TRUE(), BLANK())
So for example if I create the following measures, the Today one just being used for illustration.
Start_date:=FIRSTDATE( Dates[Date] )
End_Date:=LASTDATE( Dates[Date])
Today:=TODAY()
EndPhased:=CALCULATE( LASTDATE( Dates[Date] ), Dates[Past_dates] = TRUE())
Which when added to an empty pivot table evaluate to the following.
Note that you would want to have year somewhere in the pivot if you have multiple years of data.
The idea of having the Past flag is to keep from counting days where they would not be any data due to being in the future. So for example in September it would only use 11 days of sales and not the full 30.
As the below example shows, the finding of the start and end date even work on a Quarter basis.
So now that we have a way to get the Start and End date of a period, the next step is adding it into our Calculated measure.
In the below example, we are iterating though every unique Category name. Within the category, we are summing the units sold, and then dividing by the number of days between EndPhased and Start_Date + 1. Then averaging the results by the number of categories that have data in that period.
Average:=AVERAGEX (
VALUES ( Data[Category] ),
CALCULATE ( DIVIDE ( SUM ( Data[Units] ), [EndPhased] - [Start_date] + 1 ) )
)
It seems to me that you need to have an underlying row with the zero value in it (in your initial Data table). Right now, you don't actually have a zero value for B on 02/01/2017. If you add a row with the values | 02/01/2017 | B | 0 | I believe you will see that the average accounts for it. As things stand for you right now, I believe the pivot table actually reflects no value (blank) rather than zero value, so the zero isn't currently counted for the average.
I think the best way is to add the missing zeroes, using UNION function:
SUMMARIZE(
Data,
Data[Category],
"Average",
AVERAGEX(
UNION(
SUMMARIZE(
Data,
Data[Date],
"Sum of Units",
SUM(Data[Units])
),
ADDCOLUMNS(
EXCEPT(
ALL(Data[Date]),
VALUES(Data[Date])
),
"Sum of Units",
0
)
),
[Sum of Units]
)
)
I'm trying to show the total closing balance by month for the dataset below:
[Tranche] [Maturity Date] [Balance]
T1 1-Jan-16 1000
T2 2-Jan-16 200
T3 1-Jan-16 3000
T3 3-Jan-16 2900
T1 31-Jan-16 1000
T2 1-Feb-16 200
T3 31-Jan-16 3000
T3 2-Feb-16 2900
I have joined the dataset (table LoanSched) with a dates lookup table (Dates).
Here's the DAX calculated field formula:
=CALCULATE (
SUM(LoanSched[Balance]),
FILTER ( Dates, Dates[FullDate] = MAX(LoanSched[Maturity Date]) )
)
However, I get the result below which is incorrect. Since Tranche T2's balance ends on a date earlier than T3, the balance is excluded in the monthly total. The way the dataset works, is that the total balance should included balances that appear on the last day of each month and tranche. I'm missing the tranche condition.
I need to calculate the correct balances (highlighted in yellow) below:
So what you have here is a form of a semi-additive measure, though I don't quite understand that grand total as it relates to the subtotals - what it says to me is that each "tranche-maturity date" combination is an independent instrument, so it doesn't entirely make sense to use traditional time intelligence - like instead of months that could just be some other arbitrary hierarchy. Is that correct?
Anyway, based on your criteria, what you want is basically
a calculated measure that returns the last non blank balance within a month for a given tranche;
another measure which adds up that measure for each tranche to get a "maturity month balance";
and then a final measure that adds up that measure for each maturing month to get a "total balance".
For #1, this is the traditional formula:
TrancheEndingBalance := CALCULATE (
SUM ( ClosingBalance[Balance]),
LASTNONBLANK (
Dates[FullDate],
CALCULATE ( SUM ( ClosingBalance[Balance] ) )
)
)
And then #2 is just a SUMX across tranches:
MaturityMonthEndingBalance :=
SUMX ( VALUES ( ClosingBalance[Tranche] ), [TrancheEndingBalance] )
And #3 a SUMX across maturity months:
TotalEndingBalance :=
SUMX ( VALUES ( Dates[MonthYear] ), [MaturityMonthEndingBalance] )
Please note these measures essentially only work for the layout you've described, but it sounds like that's the only way to get at the correct balance for a given set of tranches and maturity dates, so form follows function, as it were.