Update SLA Status - powerbi

Need Help with DAX query, I have below data set
DAX
SLA_miss =
IF (
[Task_Status] <> "Task Completed"
&& [Task_Status] <> "Cancelled"
&& Task_data[Status] = "History",
IF (
Task_data[Task_due_date_only] < TODAY (),
"Breached",
"Complete"
),
"On track"
)
I want to write Dax query to track if SLA was missed.
If task due date is in past and Task status is "Cancelled" or "Task Completed" SLA miss should say "Complete" Else say "breached". If date is in future SLA miss should say "on track"
any idea?

It's not about formats, it's about logic. Try this:
SLA Status =
IF(
Task_data[Task_due_date] >= TODAY(),
"On track",
IF(
OR(
Task_data[Task_Status] = "Task Completed",
Task_data[Task_Status] = "Cancelled"
),
"Complete",
"Breached"
)
)

Related

Dax Counts at end of each month

I have a measure that depending on a "before" date slicer shows how many accounts were active at any given point in the company's history. I'm being asked to show month over month growth (end of month 1 compared to end of month 2 totals) but that's difficult given my measure needs a date slicer with one date value to return a total.
Active_Accounts =
CALCULATE (
COUNTX (
FILTER (
VALUES ( 'TEST CHARGES'[BI_ACCT] ),
[total as of date] > 0
),
[BI_ACCT]
)
)
link to sample file
https://www.dropbox.com/s/pewpm85wogvq3xf/test%20active%20charges.pbix?dl=0
if you move the slider you'll see the active accounts total change to show at that time in history how many accounts had an active charge. What I'm hoping to add to the dashboard is a measure that can be placed on a table of month end values and show the active accounts at that time so I can do month to month comparisons.
Active Accounts =
var month_end =
ENDOFMONTH (
LASTNONBLANK (
'Test Charges Date Table'[Date],
CALCULATE ( DISTINCTCOUNT( ( 'TEST CHARGES'[BI_ACCT] ) )
)
)
)
var last_date =
CALCULATE(
LASTNONBLANK('TEST CHARGES'[CHG_DATE], ""),
'TEST CHARGES'[CHG_DATE] <= max('Test Charges Date Table'[Date])
)
var num_of_actives =
CALCULATE(
Countx(
Filter(
Values('TEST CHARGES'[BI_ACCT]),
[total as of date] > 0
) , [BI_ACCT]
),
last_date <= month_end
)
return num_of_actives
As Peter advices you do not need Calculate() to show total in the card and using of Calculate() reduces speed of calculation. In your case speed is reduced with no reason.
There are no need to have a special column for month - use date hierarchy for row and just exclude day and quater levels.
Then add the measure to the visual table/matrix
Cummulative Count =
Calculate(
[Active_Accounts]
,'Test Charges Date Table'[Date]<=MAX('Test Charges Date Table'[Date])
)
Cummulative Count prevMonth =
Calculate(
[Cummulative Count]
,PARALLELPERIOD('Test Charges Date Table'[Date],-1,MONTH)
)

Eliminating repetitive Storage Engine queries in Power BI

Please see the Power BI model file attached here. I have an Activity table and I'd like to plot on a Line chart, the number of users that were active in the last 365 days as on the date of X Axis.
Hence, I created a date table, but it is not related as the purpose of this table is only to use in the X Axis or date filtering, and all metrics are calculated for the 365 days prior to the date of calculation.
The below DAX formula works, but if analysed in DAX Studio, there is one storage engine query for every date in the X Axis. This is really slow in my actual model file and I am looking for help optimising it.
Active Users =
var latestDate = MAX('Calendar'[Date])
RETURN
CALCULATE(
DISTINCTCOUNT('Activity Details'[Group User ID]),
ALL('Calendar'[Date]),
'Activity Details'[Event Date] <= latestDate,
'Activity Details'[Event Date] >= (latestDate - 365)
)
EDIT
The following DAX formula queries storage engine only once, but spends way more time in formula engine.
Active Users =
var latestDate = MAX('Calendar'[Date])
RETURN
CALCULATE(
SUMX(
SUMMARIZE(
'Activity Details', 'Activity Details'[Group User ID],
"Last Event", MAX('Activity Details'[Event Date])
),
1
),
ALL('Calendar'[Date]),
'Activity Details'[Event Date] <= latestDate,
'Activity Details'[Event Date] >= (latestDate - 365)
)

Performance Problems with DAX expression

I'm having a huge problem with performance in the below DAX measure.
Amount = CALCULATE (
SUMX (
'Financial All Scenarios',
IF (
SELECTEDVALUE ( 'Report Options'[Currency], "CD" ) = "USD",
'Financial All Scenarios'[GLAmountUSD],
IF (SELECTEDVALUE ( 'Report Options'[Currency], "CD" ) = "CD",
'Financial All Scenarios'[GLAmountCD],
'Financial All Scenarios'[GlAmountDoc]
)
)
)
)
This DAX measure does has the following. There is a disconnected filter table called Report Options, which has 3 a field called Currency with 3 values in it CD, USD, and DOC. This slicer is used to control which field is summed up from the fact table Financial All Scenarios. If nothing is selected from the Report Options table it defaults to CD.
I have a report that has a bunch of data on it and it returns in a second when I have the Currency Report Option slicer on the report, but nothing selected. As soon as I select the CD option it is spinning forever and not returning.
How can I adjust this DAX measure so that it performs well.
Iterative functions tend to be expensive. How about refactoring like this?
Amount =
SWITCH (
SELECTEDVALUE ( 'Report Options'[Currency], "CD" ),
"USD", SUM ( 'Financial All Scenarios'[GLAmountUSD] ),
"CD", SUM ( 'Financial All Scenarios'[GLAmountCD] ),
SUM ( 'Financial All Scenarios'[GlAmountDoc] )
)

How to note if an indicated action has any future actions occur after it in Power BI

I have a single table with the following columns: User ID, Activity Date, and an indicator column. I'm trying to note if any rows with the indicator have other indicated actions occur after them grouped by each individual user.
Below is an example of what the table looks like and what the desired output (calculated column) is:
Any help on this DAX problem would be greatly appreciated. Thank you
Check the for the latest indicated date for the User ID and check if it's after the current one.
HasLaterIndicators =
VAR LatestDate =
CALCULATE (
MAX ( Table[Activity Date] ),
ALLEXCEPT ( Table, Table[User ID] ),
Table[Indicator] = "X"
)
RETURN
IF ( Table[Indicator] = "X" && Table[Activity Date] < LatestDate, "Yes" )

How do I Fix My Nested If Statements to show all the desired output, and not just a select few?

I'm creating a report whereby I'd like to filter the records, by whether they are expired, expiring in a year or they have started their retention period or just valid data using a single column.
Below is my calculated column to help me achieve that.
The problem, however, is that the "Records on retention period" is not showing on its own, but when I choose the rest of the options I can see it's value in the displayed results.
How do I check that first the record is not expired before checking if it has started the retention period.
I've tried rearranging the ifs but the results are not okay when I tamper.
here is my formula
Record Status =
IF(
Records[Destruction Date]<>BLANK() && Records[Destruction Date] <= Today() ,
"Expired Records" ,
IF(
Records[Destruction Date]<>BLANK() && YEAR(Records[Destruction Date]) >= YEAR(Today())+1 ,
"Records Expiring In An Year",
IF(
Records[Retention Begins]<>BLANK() && Records[Retention Begins]<=TODAY() ,
"Records on Retention Period",
"Valid Records"
)))
I expect to get: Expired Records, Records Expiring In An Year, "Records on Retention Period", or "Valid Records".
To enable one to filter during visualization.
I could find logical errors in the calculation of Records Expiring In An Year & Records on Retention Period, see if the following formula works,
Record Status =
IF(
Records[Destruction Date]<>BLANK() && Records[Destruction Date] <= Today() ,
"Expired Records" ,
IF(
Records[Destruction Date]<>BLANK() && YEAR(Records[Destruction Date]) <= YEAR(Today())+1 ,
"Records Expiring In An Year",
IF(
Records[Retention Begins]<>BLANK() && Records[Retention Begins] >= TODAY() ,
"Records on Retention Period",
"Valid Records"
)))