Previous Day in Power BI - powerbi

This may be a really simply one but cannot get this to work.
Invitations_Daily =
CALCULATE (
DISTINCTCOUNTNOBLANK ( AppUser[UserId] ),
USERELATIONSHIP ( AppUser[DateInvitedID], 'Date'[DateId] ),
FILTER (
'Date',
'Date'[DateId]
= SELECTEDVALUE ( 'DateSelector'[DateId], MAX ( 'DateSelector'[DateId] ) )
)
) + 0
I have a measure and want the previous days value. When I put in a -1 then ))+0 it gives me 0, instead of the previous day value. Is there something obvious I am missing or is there something else wrong with my data model etc ?

Related

How to calculate headcount in PowerBI

I have some problem with the HR Dashboard, where I can't get it to work properly.
I have the following visuals:
Visual for HR Dashboard
The headcount code is as follow:
Headcount = CALCULATE (
DISTINCTCOUNT ( FactTable[EmpID]),
FILTER ( ALL(FactTable), FactTable[EmploymentStatus] = "Active" )
)
The problem is, that the visual doesn't slice on the seniority.
Need help.
I have try with some sample data, i guess the issue here is due to you are using filter function, you can try my method if the problem can be solved:
1)I have this original sample table
I have created a measure to count the total employee still with company
Total count = CALCULATE(COUNT(Sheet1[ID]),Sheet1[Status] = "active")
3)My scorecard has displayed the total count correct for with junior slicer
First its bad maner to write code like this:
CALCULATE (
DISTINCTCOUNT ( FactTable[EmpID] ),
FILTER (
ALL ( FactTable ),
AND (
FactTable[DateofHire] <= MIN ( 'Kaldt funktion'[Date] ),
OR (
FactTable[DateofTermination] = BLANK (),
FactTable[DateofTermination] >= MAX ( 'Kaldt funktion'[Date] )
)
)
)
)
A good practice is to use ALL with columns that you really need in your filter. Second instead of comparing column = BLANK() use function ISBLANK(Table[ColumnName]). You also should compare SELECTEDVALUE to get the correct data. (unfortunately, you don't post any samples, and I don't know how your data looks like I can only guess). How is correlated 'Kaldt funktion' with FactTable? Probably problem is in your MIN and MAX. We can also use && insted of AND, and || insted of OR;
CALCULATE (
DISTINCTCOUNT ( FactTable[EmpID] ),
FILTER (
ALL ( FactTable[DateofHire], FactTable[DateofTermination] ),
SELECTEDVALUE ( FactTable[DateofHire] ) <= MIN ( 'Kaldt funktion'[Date] )
&& (
ISBLANK ( FactTable[DateofTermination] )
|| SELECTEDVALUE ( FactTable[DateofTermination] ) >= MAX ( 'Kaldt funktion'[Date] )
)
)
)

PowerBI Record Changes

I have a table in PowerBI.
Table-
I need to create a custom column, that detects this flag changes.
Output should look like -
e.g= EID 3 changed flag in 2020. thats why new flag is set to 1.
this is a sample , I have multiple eids.
I'd recommend checking out this post to see different approaches for looking up previous flags.
One particular implementation might look like this (but there are lots of other ways to do the same thing):
New Flag =
VAR CurrYear = Table1[Year]
VAR PrevYear =
CALCULATE (
MAX ( Table1[Year] ),
ALLEXCEPT ( Table1, Table1[EID] ),
Table1[Year] < CurrYear
)
VAR PrevFlag =
CALCULATE (
SELECTEDVALUE ( Table1[Flag] ),
ALLEXCEPT ( Table1, Table1[EID] ),
Table1[Year] = PrevYear
)
RETURN
IF ( ISBLANK ( PrevYear ) || Table1[Flag] = PrevFlag, 0, 1 )
This finds the previous year, if it exists, using a max (in case the years aren't contiguous), then looks up the flag for that particular year, and finally checks if the current flag differs from the previous flag (if there is a previous flag).

DAX subquery measure?

I'm struggling with a DAX query and wondered if you could help?
Consider this table (or visualisation) called 'Builds':
Build....App....Status
Build1...App1...UAT
Build1...App2...Complete
Build2...App1...Complete
Build2...App2...Complete
I would like to add a measure column called 'AppsOutstanding' to show a count of Apps for that Build that aren't 'Complete'. Like so:
Build....App....Status......AppsOutstanding
Build1...App1...UAT.........1
Build1...App2...Complete....1
Build2...App1...Complete....0
Build2...App2...Complete....0
I almost need to do a 'subquery' measure!? Something like:
SELECT COUNT(Status) FROM Builds
WHERE Build = [The Build In This Row]
AND Status <> 'Complete'
I'm a bit stumped how to translate this into DAX? Here is my unsuccessful attempt:
AppsUnavailable = CALCULATE (
count(Builds[Build]),
CALCULATETABLE (
SUMMARIZE ( Builds,Builds[Status] ),
Builds[Status] <> "Complete"
))
Thanks in advance!
UPDATE
I've tried this, but the count isn't working, and also this DAX filters "Complete" statuses out of my actual results! Which i don't want. I only want to filter the "Complete" statuses out of my count measure....
AppsUnavailable =
CALCULATE (
COUNT ( Builds[Build] ),
FILTER (
ALL ( Builds[Build] ),
Builds[Build] = SELECTEDVALUE ( Builds[Build] )
),
FILTER (
ALL ( Builds[Status] ),
Builds[Status] <> "Complete"
)
)
UPDATE 2
I think I'm doing something fundamentally wrong. I've really dumbed it down to just find other 'Builds' with the same name, and it still only returns 1's!
AppsUnavailable =
CALCULATE (
COUNT ( Builds[Build] ),
FILTER (
ALL ( Builds[Build] ),
Builds[Build] = SELECTEDVALUE ( Builds[Build] )
)
)
UPDATE 3
This query (when testing on a single table (no joins) sample) produces this:
Build....App....Status......AppsOutstanding
Build1...App1...UAT.........1
Build1...App2...Complete....0
Build1...App2...UAT.........1
Build2...App1...Complete....0
Build2...App2...Complete....0
But i actually need this:
Build....App....Status......AppsOutstanding
Build1...App1...UAT.........2
Build1...App2...Complete....0
Build1...App2...UAT.........2
Build2...App1...Complete....0
Build2...App2...Complete....0
So Build1 has 2 Apps that are not complete.
I then need to look into why I'm getting all 1's in the 'live' environment. It must be to do with filtering on 2 tables as opposed to 1....
You can replace [The Build In This Row] with SELECTEDVALUE ( Builds[Build] ).
Try this:
AppsUnavailable =
CALCULATE (
COUNT ( Builds[App] ),
FILTER (
ALL ( Builds[Status], Builds[Build] ),
Builds[Build] = SELECTEDVALUE ( Builds[Build] )
&& Builds[Status] <> "Complete"
)
) + 0
powerBI Table visualization internal use SUMMARIZECOLUMNS which is removed row without data from the measure. You have 2 options:
-Right click on GroupBy Column -> "Show item with no data"
-Add +0 to calculation after the last parenthesis
UPDATE:
CALCULATE (
COUNT ( YourTable[App] ),
FILTER (
ALL ( YourTable[App], YourTable[Build], YourTable[Status] ),
YourTable[Build] = SELECTEDVALUE ( YourTable[Build] )
&& YourTable[Status] <> "Complete"
)
) + 0

Power BI: Measure is not ignoring Slicer Filter

My Dax Query is correctly bringing back the expected data. The one caveat, I can't seem to ignore an outside slicer to the visual for this one particular calculation. What am I doing wrong?
xxPY_TrafficSum = CALCULATE (
[xPY_TrafficSum],
DATESBETWEEN (
DimDate[FullDate],
DATE (
YEAR ( ALLSELECTED ( DimDate[FullDate] ) ) - 2,
MONTH ( ALLSELECTED ( DimDate[FullDate] ) ),
DAY ( ALLSELECTED ( DimDate[FullDate] ) ) + 1
),
DATE (
YEAR ( ALLSELECTED ( DimDate[FullDate] ) ) - 1,
MONTH ( ALLSELECTED ( DimDate[FullDate] ) ),
DAY ( ALLSELECTED ( DimDate[FullDate] ) ) + 1
)
),
ALL ( DimDate[IsLastDayOfMonth], DimDate[IsLastDayOfMonth] )
)
I don't think you have to specify the column twice within the ALL function. Although I am not sure how this would affect the calculation, you can give it a try:
All(DimDate[IsLastDayOfMonth])
One more thing you could try is to move the position of the ALL function within the calculation. i.e) switch the positions of the DATESBETWEEN and the ALL functions. If your issue is still not resolved, it would be great if you can share a sample data/file for us to look at.

Create measure to calculate % change from distinct values in a column

Situation:
I have a column in my table with values representing weeks of the year.
Each week number has their respective total counts of purchases on another column. When I use a matrix visual and put that specific column in the Columns section it separates them distinctively which is what I want. How can get the % change from one week to another?
Table looks like this:
Objective:
Create a measure that can divides column 2 by column 1 to get the % change.
Layout of Matrix:
Ideally I would like to have a third column to calculate the values in column 6 by the ones in column 5.
OK, here is one solution:
Delta :=
VAR Week5 =
CALCULATE ( SUM ( 'Table'[Total] ), FILTER ( 'Table', 'Table'[Weeks] = 5 ) )
VAR Week6 =
CALCULATE ( SUM ( 'Table'[Total] ), FILTER ( 'Table', 'Table'[Weeks] = 6 ) )
RETURN
IF (
SUM ( 'Table'[Total] ) = SUMX ( ALL ( 'Table' ), 'Table'[Total] )
|| SUM ( 'Table'[Total] )
= SUMX (
FILTER ( ALL ( 'Table' ), 'Table'[Cohort] = MAX ( 'Table'[Cohort] ) ),
'Table'[Total]
),
100*DIVIDE ( Week6 - Week5, Week5 ),
BLANK ()
)
I tested it and it works:
BUT because the way your data is structured, it makes it very difficult (for me) to make this pretty. But hey, it works!! ;) I wasn't sure which direction you needed the delta but that is a simple change in the measure from this:
100*DIVIDE ( Week6 - Week5, Week5 )
To this:
100*DIVIDE ( Week5 - Week6, Week6 )
Hope this help!