Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi!
I'm trying to calculate distinctcount from products tested in certain period of time. I got [SerialNumber]-column to identify exact product. I should count only those tests that are new for the time period (Test can fail and the same serial number will be tested again, but I don't want to count Re-tests).
I'd like to find a Dax measure that checks when the first test of a serial number took place and excludes those from the count if they won't fit the time frame.
I'm using separate calender table to get the time intelligence right. It's linked to [LocalDate]-column included in TestResults-table. TestResults-table is in import-mode if that helps with formulating the DAX.
I've made the measure which returns corrct date for first entry of a serial number, but when filtering the visuals, It still counts those re-tests in.
Picture below shows my problem. As you can see FirstPVM on the left says Serial number with 1000 is tested first time in 23.6. but still on the right side graph it still shows up on the 24.6 . Description on the right side says basically OK(re-tested) for the 1000 SN.
Method for retrieving the first test date is following:
Solved! Go to Solution.
// T is your table with tests.
[Absolute First Test Date] =
// This does not observe any
// filters on dates. Just returns
// the very first test date throughout
// the whole data set.
IF( HASONEFILTER( T[SerialNumber] ),
var __serial = SELECTEDVALUE( T[SerialNumber] )
var __firstTestDate =
MINX(
CALCULATETABLE(
T,
T[SerialNumber] = __serial,
ALL( T )
),
T[TestDate]
)
return
__firstTestDate
)
[Is First Test Date in Timeframe] =
// Returns TRUE if for the current SN
// its absolute first test date is in
// the selected period of time. If not,
// returns FALSE and returns BLANK if
// more than 1 SN is being actively filtered.
IF( HASONEFILTER( T[SerialNumber] ),
[Absolute First Test Date]
IN VALUES( Calendar[Date] )
)
[# SNs with First Tests in Timeframe] =
// Gets the number of SNs that have
// their very first test date in the
// selected time frame.
var __result =
SUMX(
VALUES( T[SerialNumber] ),
1 * [Is First Test Date in Timeframe]
)
return
IF( __result > 0, __result )
// T is your table with tests.
[Absolute First Test Date] =
// This does not observe any
// filters on dates. Just returns
// the very first test date throughout
// the whole data set.
IF( HASONEFILTER( T[SerialNumber] ),
var __serial = SELECTEDVALUE( T[SerialNumber] )
var __firstTestDate =
MINX(
CALCULATETABLE(
T,
T[SerialNumber] = __serial,
ALL( T )
),
T[TestDate]
)
return
__firstTestDate
)
[Is First Test Date in Timeframe] =
// Returns TRUE if for the current SN
// its absolute first test date is in
// the selected period of time. If not,
// returns FALSE and returns BLANK if
// more than 1 SN is being actively filtered.
IF( HASONEFILTER( T[SerialNumber] ),
[Absolute First Test Date]
IN VALUES( Calendar[Date] )
)
[# SNs with First Tests in Timeframe] =
// Gets the number of SNs that have
// their very first test date in the
// selected time frame.
var __result =
SUMX(
VALUES( T[SerialNumber] ),
1 * [Is First Test Date in Timeframe]
)
return
IF( __result > 0, __result )
Watch out for your filter context. Use ALLSELECTED() or KEEPFILTERS()
How does it works in this case? Where should I put it? on FirstPVM-measure or AllTestedProducts?
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
47 | |
26 | |
19 | |
14 | |
10 |
User | Count |
---|---|
57 | |
49 | |
44 | |
18 | |
18 |