DAX query for KPI tracking - powerbi

i am trying to write a query in order to track penalty in case of KPI failure.
eg. if in month of Oct my PI is failed 98% i get a retention if fail again following month not i get another retention i get deduction. In case one month its 98% and next month i pass i get money back.
below is the formula in excel need to change them in DAX any suggestions please.
Frist month retention formula =IF(AND(F4>=0.98,F4<1),E4,"")
**following month deduction ** =IF(AND(F5<1,F5>=0.98,J5<1,J5>=0.98),E5,IF(AND(J5<0.98,F5<0.98),I5,IF(AND(F5<1,F5>=0.98,J5<0.98),E5+I5,IF(AND(F5=1,J5<0.98),I5,""))))
refund of retention in case of pass =IF(AND(N5=1,J5<1,J5>=0.98),-K5,IF(AND(N5<1,N5>=0.98,J5<1,J5>=0.98),M5,IF(AND(J5=1,N5<1,N5>=0.98),M5,IF(AND(J5<0.98,N5<1,N5>=0.98),M5,""))))

Related

DAX query for excel formulas for kpi tracking

i am trying to write a query in order to track penalty in case of KPI failure. eg. if in month of Oct my PI is failed 98% i get a retention if fail again following month not i get another retention i get deduction. In case one month its 98% and next month i pass i get money back.
below is the formula in excel need to change them in DAX any suggestions please.
how to translate below formulas in DAX, as my dax knowledge is limited
Frist month retention formula =IF(AND(F4>=0.98,F4<1),E4,"") **following month deduction ** =IF(AND(F5<1,F5>=0.98,J5<1,J5>=0.98),E5,IF(AND(J5<0.98,F5<0.98),I5,IF(AND(F5<1,F5>=0.98,J5<0.98),E5+I5,IF(AND(F5=1,J5<0.98),I5,""))))
refund of retention in case of pass =IF(AND(N5=1,J5<1,J5>=0.98),-K5,IF(AND(N5<1,N5>=0.98,J5<1,J5>=0.98),M5,IF(AND(J5=1,N5<1,N5>=0.98),M5,IF(AND(J5<0.98,N5<1,N5>=0.98),M5,""))))

Rolling Average Prediciton for Future 30 Days in DAX

I am working on a forecasting graph that will be pulling in data from SQL through power query. The graph will have slicers and filters available to the user to analyze different populations. I am currently being asked to provide a rolling average for each day of the next month but will update daily as more data becomes available. I need 30 days of rolling average that occur after the current date. Using the prior days rolling average calculation. This has to be completed in dax to allow the filters and slicers to work appropriately. The rolling average looks 14 days back.
Any ideas on how to best proceed would be greatly appreciated.
Below is a table of data to show how this looks in excel:

How to graph by 7 day periods in Power BI

Power Bi gives you the option to look at data by Year, Quarter, Month, and Day. I want the ability to look at data by 7 day periods that start on a specific date (not necessarily Monday or Sunday). How is the best way to accomplish this? I am guessing it will be with a measure but I can't quite figure out what the measure should look like?
Here I know I can assign a day of the week to each row and then use Week Day on my date axis. My problem is I need to be able to put "Tuesday" in the second parameter instead of either 1. Sunday or 2. Monday.
Week Number = WEEKNUM(Sheet1[Date],2)
Thank you in advance!
IIUC, the following might work:
Week number = WEEKNUM(DATEADD([Date],1,DAY),2)

Cumulative/Rolling Sum Blank Dates

I'm currently working on inventory reconciliation, and I've struggling to fill all days of the calendar with the cumulative sum of product we're currently storing:
Inventory level ($). = CALCULATE(SUM(ledger[cost]),FILTER(ALL(DimDate[Date]),DimDate[Date]<=MAX(ledger[Document Date])))
As you guys might notice it has at least 90% of all dates filled, however if we look closely to the graph, we can appreaciate March 5th of 2016 is missing just due to the fact there was no transaction during that day resulting on a blank value. However I'm trying to accomplish retrieving the previous day balance for those days with no transactions. e.g: for March 5th should have $17,038,462.32 (balance for the previous day March 4th).
I'm trying to work on another clause into the measure with functions such as EARLIER or LASTDATE, however I haven't been succesful.
Any insight or solutions works well thank you. Have a nice day.
You are using a wrong date field in your measure. Change it to the field from the Date table:
Inventory level. =
CALCULATE(
SUM(ledger[cost]),
FILTER(ALL(DimDate[Date]),DimDate[Date]<=MAX(DimDate[Date])))

Calculate rates from previous month based on current month in order to make then visually comparable

Maybe this is an easy one but since I’m very new in DAX and PowerBI I can’t figure it out. My database has daily data ranging from MAY/17 to JUN/17 (and it’ll still going in the future). It has information of DATE, DAY, YRMTH (year-month), QT_APRV (approved customers) and QT_TOTAL (total consumers). Sample below (using Excel just to be quicker):
I wanted to create in PowerBI a bar chart with QT_TOTAL per day and a line chart with approved rate of consumer. For the rate, I used:
APPRV_RT = SUM(database[QT_APRV]/SUM(database[QT_TOTAL])
And then, selecting only a month by time in the chart (just like I want), I have:
Perfect, but now I want to create a new line chart, showing the approved rate in each respective day of the last month. Using my example, when june data are select, the first line chart has to show the daily approved rate of june AND the other the approved rate of may, in order to make it comparable (june1 -> may1; june12 -> may12 and so on). Here’s what I want:
How to make this automatically, in order to make each month comparable with the previous? I thought about some DAX formula involving a sum with filtering current month minus 1, I don’t know how to do it.
Any ideas?
UPDATE (07/08/2017)
I tried what Rasmus Dybkjær suggested me, and I thing I'm in the right path.
APPROVED_RATE_PREVIOUS_MONTH = CALCULATE([APPROVED_RATE_CURRENT_MONTH];PARALLELPERIOD(dCalendario[DataBase];-1;MONTH))
However, it returned the approved rate from the previous month as a whole (67,0% in May), not each day as I wanted:
Any suggestions?
You should be able to use the DAX function called PARALLELPERIOD() for this purpose. The PARALLELPERIOD() function takes a date column and shifts it a number of periods back or forward.
For example, you could use it like this to calculate your approved rate shifted one month back:
ApprovedRateLM =
CALCULATE(
DIVIDE(
SUM(database[QT_APRV]),
SUM(database[QT_TOTAL])
),
PARALLELPERIOD(database[Date],-1,month)
)
Note that it is important that your [Date] column contains a date type. Otherwise the PARALLELPERIOD function will not work.