How to stop showing a running total in Power BI - powerbi

I have a running total in power BI as a line graph.
I want to only show my running total line up to the most recent months data (september 22), in order to get the flat line off the visualisation, so I can forecast the rest of the line.
My cumulative total measure is :
'''Actual Spend YTD =
CALCULATE (
SUM ( CombinedUsageFact[TargetCost] ),
FILTER (
ALLSELECTED ( MonthNumDim[DateMonth]),
ISONORAFTER ( MonthNumDim[DateMonth], MAX ( MonthNumDim[DateMonth] ), DESC )
)
)'''
I need my axis to display up to year end (march 2023) like it does.
What can I do to stop my cumulative line at the most recent data?
Thanks
Would attach images/sample but it says there's a problem with the server!

To get the cumulative calculation to stop on the last period with data, filter the last date by the fact table:
Actual Spend YTD =
VAR maxDate =
CALCULATE ( MAX ( MonthNumDim[DateMonth] ), CombinedUsageFact )
RETURN
CALCULATE (
SUM ( CombinedUsageFact[TargetCost] ),
FILTER (
ALLSELECTED ( MonthNumDim[DateMonth] ),
ISONORAFTER ( MonthNumDim[DateMonth], maxDate, DESC )
)

Related

Running total with a slicer in Powerbi

I am trying to find the running total by month, it worked using the following measure but only without using a slicer for the category "BLK":
With Date = VAR MaxDate =
MAX ( 'Calendar Table'[Date] ) RETURN
CALCULATE (
SUM ( 'Injuries'[Total] ),
FILTER (
ALL ( 'Injuries'[Classification] ),
'Injuries'[Classification] = "FAC"
),
FILTER ( ALLSELECTED ( 'Calendar Table' ), 'Calendar Table'[Date] <= MaxDate)
)+0
The result was only accurate when I don't apply the Category slicer "BLK", I tried a different measure:
With BLK = CALCULATE( SUM('Oxy Oman Personal Injuries'[Total]),
FILTER (
ALL ( 'Injuries'[Classification] ),
'Injuries'[Classification] = "FAC"
), ALLSELECTED('Blocks'[BLK]) )+0
The above gave me something similar to the actual data, it did not sum up the numbers.. at least it gave me the correct total of a the category selected = 5 while the first measure gave the total wrong = 4.
Here is a screenshot of the results for both measures with and without a slicer:
Without BLK slicer:(With Data gave me what I wanted)
Using one Category in the BLK Slicer:
How can I fix that?

PowerBI Last N Months Trend Line - Ignore All Date Filters

Have a simple, 2 table model: [Sales]*-[Calendar] with sales that span from 1/1/2021 to yesterday. Day grain. Calendar is a standard date dimension.
Need: I want a line chart that shows the sales trend for each day since the first of the month, 3 months back, to yesterday.
I want this line chart measure to ignore the influence from all Calendar[Date] slicers/filter that happen to be on the report.
I understand I can use the "edit interactions" feature and stop the Date slicers from affecting the trend line - and that works - with this code.
However, I want to learn how to ignore these external filter affects within DAX & not rely on using the edit-interaction feature.
I've gotten this far. This code calcs the measure I want, but a date slicer on the report affects it and I don't want it to. What am I missing?
Total $ Last 3 Months Trend =
VAR __monthsBack = 3
VAR __endDate =
CALCULATE ( MAX ( Sales[SalesDate] ), ALL ( 'Calendar' ) )
VAR __endDateMinus_NMonths =
EDATE ( __endDate, - __monthsBack )
VAR __firstDate =
DATE ( YEAR ( __endDateMinus_NMonths ), MONTH ( __endDateMinus_NMonths ), 01 )
RETURN
IF (
MAX ( 'Calendar'[Date] ) <= __endDate
&& MAX ( 'Calendar'[Date] ) >= __firstDate,
CALCULATE (
[Total $],
FILTER (
'Calendar',
'Calendar'[Date] >= __firstDate
&& 'Calendar'[Date] <= __endDate
),
REMOVEFILTERS ( 'Calendar'[Date] )
),
BLANK ()
)

PowerBI using customer %% as X-Axis

I'm looking to create a line graph with accumulated revenue and -gross profit as 0-100% Value Lines on the Y-axis and then have 0-100% of the amount of customers on the X-axis.
I've managed to get the Y-axis and the accumulated lines working using Months on the X-axis. That's not the hard part though, I need to get customer count 0 - 100% on the X-AXIS and I cannot seem to figure it out.
No particular parameters desired i.r.t. the customer accumulation. We just want to be able to see how much the sales are rising along with the relative distinct count of customers in our database.
This way we can see that the first 20% of customers hold i.e. 50% of the revenue etc.
It's a bit weird, I've tried adding custom columns to calculate the percentage of a customer to the grand total of distinct counts but I cannot seem to get it to accumulate. Perhaps i'm looking entirely in the wrong direction and there's a better solution to this. I'd appreciate any help!
KR,
Maarten
You can make the x-axis as a calculated column. If you don't already have a Customer dimension table, then you can create a new calculated table as follows:
CustomerAxis =
VAR CustomerRev =
ADDCOLUMNS (
DISTINCT ( Data[Customer] ),
"CustomerRevenue", CALCULATE ( SUM ( Data[Revenue] ) )
)
VAR TotalRev = SUM ( Data[Revenue] )
VAR TotalCustomers = DISTINCTCOUNT ( Data[Customer] )
VAR CumulativeCols =
ADDCOLUMNS (
CustomerRev,
"CumulativeRevenue",
SUMX (
FILTER ( CustomerRev, [CustomerRevenue] >= EARLIER ( [CustomerRevenue] ) ),
[CustomerRevenue]
),
"CumulativeCount",
COUNTROWS (
FILTER ( CustomerRev, [CustomerRevenue] >= EARLIER ( [CustomerRevenue] ) )
)
)
RETURN
ADDCOLUMNS (
CumulativeCols,
"% of Customers", DIVIDE ( [CumulativeCount], TotalCustomers ),
"% of Revenue", DIVIDE ( [CumulativeRevenue], TotalRev )
)
Then you can drag and drop these last two % columns into a line chart to get the desired curve.
PBIX file I created: https://www.dropbox.com/s/w6trky7t0h42gkp/Pareto.pbix?dl=0

How to calculate average inventory in power bi?

I would like to calculate average inventory as per month. I have used date filter in the report.
We have average inventory formula as (beginning inventory + closing inventory)/2
I have following logic to calculate average inventory.
If we choose month as a march then the amount of the beginning inventory will be the inventory of the march and the amount of the closing inventory will be the inventory of the the last month and we need to sum these beginning and closing inventory and then take averages of them.
So how can we write above logic in DAX expression?
I have attached the data with expected output.
Please click on this link to see the data with the expected output.
Average Inventory =
VAR _latestdate =
CALCULATE ( MAX ( 'Table'[Date] ), ALL ( 'Table'[Date] ) )
RETURN
(
SUMX ( 'Table', 'Table'[Inventory Sum Amount] )
+ CALCULATE (
SUMX ( 'Table', 'Table'[Inventory Sum Amount] ),
FILTER ( ALL ( 'Table' ), _latestdate = 'Table'[Date] )
)
) / 2
You should have a proper date formatted column...

How to work out Attrition for Staff members with a Start & End Date in Power BI?

I have a table with Staff data with columns DateEmployed & TerminationDate.
I would like to work out the number of people that started & left (which I used a count formula) as well as the net growth for all date periods.
The formula would count each DateEmployed as 1 & if an individual does not have a Termination Date then it would not count it.
e.g. 4 people starts in June 2016 & 2 leaves in June 2016 giving me a net value of 2.
The issue arises further as I need a date dimension to view them for each month for each year.
I would like to display all 3 dimensions of data in one graph as well.
The data should read like the bar graphs consolidated:
enter image description here
The best practice in every case is to create a calendar/date table. Fortunately calendar tables are easy to create in Power BI. With an expression you can create it.
In Power BI / Modeling tab / New Table icon, you can create a custom date table using this expression:
DateTable = CALENDAR (DATE(2016,1,1), DATE(2016,12,31))
This expression generates dates from 2016-1-1 to 2016-12-31 so if your data expands to a wider range you have to modify it to suit to your requeriment.
Create these measures:
Starting: Measure counting the people starting in each month or year.
Starting =
CALCULATE (
COUNT ( 'Table'[FullName] ),
FILTER (
ALL ( 'Table' ),
COUNTROWS (
FILTER (
'Table',
NOT ISBLANK ( [DateEmployed] )
&& MONTH ( EARLIER ( 'Table'[DateEmployed] ) ) = MONTH ( MAX ( DateTable[Date] ) )
)
)
)
)
Ending: Measure for counting the people ending in each month or year.
Ending =
CALCULATE (
COUNT ( 'Table'[FullName] ),
FILTER (
ALL ( 'Table' ),
COUNTROWS (
FILTER (
'Table',
NOT ISBLANK ( [TerminationDate] )
&& MONTH ( EARLIER ( 'Table'[TerminationDate] ) )
= MONTH ( MAX ( DateTable[Date] ) )
)
)
)
)
Net: Total for each month:
Total = ABS([Starting] - [Ending])
Now in a bar chart or any visualization set the measures something like this: