Average Days Outstanding of ALL tickets as of certain date - powerbi

I am trying to figure out Dax for Average Days Outstanding taking into account all tickets that are open as of spec date to show trend over time.
How many days tickets are outstanding on average over the period of time and how many days outstanding on tickets as of 8/25/2020? In this case, I am taking as of today's date but I need to be able to calculate as of 8/1/2020 as well.
Per example below, I have manually calculated in excel the outcome that I am looking for but do not know how to create DAX formula to reflect that. I did it in excel to show what outcome I am trying to achieve.
In powerbi, I do have Calendar table with a date column and with relationship to ticket date.
As you can see, in my average formula I am taking into consideration all tickets that have current balance >0 as of 8/25/2020 and giving average counting prior rows ( prior tickets open as of 8/25/20).
Currently, I know to how to calculate DAX days outstanding which is difference between ticket dates and today on tickets with current balance >0 but I do not know how to include in my DAX prior days where tickets are outstanding as well.
Your help is greatly appreciated!

Try with the below logi-
running_average =
VAR current_row_date = MIN(your_table_name[payment date])
RETURN
AVERAGEX (
FILTER(
ALL(your_table_name),
your_table_name[payment date] <= current_row_date
),
your_table_name[outstanding amount column name]
)
I can see some value in "payment date" column is blank. They will produce wrong results here. You need to somehow make adjustment for those BLANK values to get correct results.

Related

PowerBI - Calculate average year from a date column

I have a table (we'll just call it MyTable) in PowerBI that includes a Date column. I have created a DateDimension table using CALENDARAUTO() with columns for the Date, Month#, MonthName, etc and created the relationship between that Date and the Date in MyTable.
I want to calculate the average year based on the records in MyTable. For example, if I have records with 1/1/2005, 1/1/2014, and 1/1/2015, the average year should be 2011.
How would I go about doing that? I've tried doing a measure of AVERAGE(DateDimension[Year]) and adding that to a Card visual, but it just shows 2.01K. If I do FORMAT(AVERAGE(DateDimension[Year]), "####"), the average is completely wrong.
Since you already have this DateDimension table, use
Average =
AVERAGEX(
MyTable,
RELATED(DateDimension[Year])
)
You can control the formatting by clicking on the measure (Average) and then using the Measure tools pane:
Set it to Whole number and no thousands operator.

Calculate daily average including zero in Power BI

I have a dataset of patients visiting several categories(SPECIALISM) of a hospital. A visit lasts a couple of hours each day. Each row in my dataset represents an hour that they are present for a certain hospital specialism.
Input
I want to calculate for each hour of the day, the number of patients that are present on average, per specialism, I used the following code (measure):
daggem = AVERAGEX(values('Date'[Date]),[distinctpat])
with distinctpat being a distinct count of patient IDs
This gives me almost the desired result, but the tales of the graph are too heavy (it shows an average of 1 patient during the night, but this 1 patient was there only on 1 specific day, normally it is zero. But the average, as I calculated, it does not include all other nights when there were zero patients. So I would like to obtain an average that is much lower (and more correct)
Output
You probably need an extra table with all the days and times. Based on the reports, you will be able to find the hours without visits
Here is an example of how to create a Date table with hours; Add relationship and use in calculation.
DatesWithHours =
var Dates = CALENDAR("2021-01-01 00:00:00", "2021-01-03 00:00:00")
var DatesHour =
GENERATE(Dates, (ADDCOLUMNS(GENERATESERIES(1,12,1),"Hours", [Date] + TIME([Value],0,0))))
return
DatesHour
That's the problem with AVERAGEX, it ignores blanks. Try a simple division instead.
daggem =
DIVIDE (
COUNTROWS ( TargetTable ),
COUNTROWS ( Dates )
)

Finding Previous year Sales in Power BI with week number

I am trying to find the Previous year sales for the same week in Power BI.I dont have any date column.
I have two table one is FACT Indicators table as shown below:
and one sales table( Fact Sales table):
I want to create one calculated field namely(Sales Previous Year) to show the previous year sales for the same week .
In 'Fact Indicators' table 'PY 52 week flag' filed shows if this week id is Previous year or not.
Week column shows the week number from 1 to 52 weeks .
Week Id shows the unique number per Market key.
'Market_Week Id Key' is the common joining key between FACT Indicators table and Fact Sales table
Please help me to find the formula for calculated field.I dont have the date field in my raw data
Every time you deal with anything related to dates, you will need to add what we call a date dimension. It will save you tons of headaches. Once you have it in you will be able to hook it into the creation of the calculated filed.
you can google power bi or ssas date dimension and find tons of information on it.
Yeah! I guess SQL Technical team can be a tough crowd.... Well! In this case, I would recommend bringing the Year into FactSales Table from Fact Indicator . You have two options here with physical relationship set up between Market Week Id Key in both tables you can build a calc column with
Year = CALCULATE(VALUES(FactIndicators[Year]))
or without relationship use LOOKUPVALUE on WeekId
Year = LOOKUPVALUE(FactIndicators[Year], FactIndicators[WeekId], FactSales[WeekId])
Sales Last Year calc colum :
SalesLastYear =
CALCULATE (
SUM(FactSales[SalesThisYear] ),
TOPN(1,
FILTER(
FactSales,
FactSales[Year] < EARLIER(FactSales[Year])
&& FactSales[Key] < EARLIER(FactSales[Key])
)
)
)

Calculate monthly Avg of daily percentage values

We have a report in Compliance% which is calculated every day. I have a requirement to calculate the Monthly Average of these daily Compliance% values.
PowerBI currently gives incorrect total value in a table format, I have attached the sample file. It is giving 56.90 in the grand total whereas I want to calculate sum(Compliance%)/count(day or month).
Could someone please help.
[
I think you need to introduce a new measure:
mDay =
IF(
HASONEFILTER(Table1[Compliance %]),
SUM(Table1[Day]),
FORMAT(
SUMX(Table1, Table1[Compliance %]) / COUNT(Table1[Day]),
"0.00%")
)
Here's the result for the month of February:
Here's another one if you also include a few values from March:
As you can see the measure responds to your table filters.
I hope it helps.

Power BI Rolling Average

I've used the new Quick Measures feature of Power BI to build a 3 month rolling average calculation and it's working well. The equation is displayed below. However, when I try to use this metric in a time series visualization, the calculations are displaying three months past the current month, but I'd like for the calculation to stop at the current month.
I've played around with the __DATE_PERIOD variable to no avail. My date filter for the page is set to show all dates in the current months or 12 months prior via a calculated column on the date table.
Is anyone aware of how I can get the visualization to end at the current month?
Average Days to Close Rolling Average =
IF(
ISFILTERED('Date'[Date]),
ERROR("Time intelligence quick measures can only be grouped or filtered by the Power BI-provided date hierarchy."),
VAR __LAST_DATE =
ENDOFMONTH('Date'[Date].[Date])
VAR __DATE_PERIOD =
DATESBETWEEN(
'Date'[Date].[Date],
STARTOFMONTH(DATEADD(__LAST_DATE, -3, MONTH)),
__LAST_DATE
)
RETURN
AVERAGEX(
CALCULATETABLE(
SUMMARIZE(
VALUES('Date'),
'Date'[Date].[Year],
'Date'[Date].[QuarterNo],
'Date'[Date].[Quarter],
'Date'[Date].[MonthNo],
'Date'[Date].[Month]
),
__DATE_PERIOD
),
CALCULATE(
'Closed Opportunities'[Average Days to Close],
ALL('Date'[Date].[Day])
)
)
)
In order to limit what is displayed within your chart, you need to filter the applicable date field so it only displays the dates you desire. In this case, you only want it to include dates <= today.
In order to automatically filter it when it is refreshed, I typically add a custom DAX column to the date table that I can filer on. In this case it would be something along the lines of:
excludeFutureDatesInd = 'Date'[Date] <= TODAY()
You can then add a visual, page, or report filter selecting all dates where [excludeFutureDatesInd] = True.
Not sure if you're still having issues with this, but I'd like to share a hack fix for those landing here. I fixed this issue by filtering on the base data (in your example, this would be "Average Days to Close"). Set a visual-level filter to include only those items where Average Days to Close > 0, and you should get the extra dates cut off the end of the graph.
So long as all of your base data passes through the filter, you should be good.