Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
kinseld5
Helper II
Helper II

Check if previous value is the same or different - Comparing data across dates

Hi.

I have a data feed of hardware used within a company that is reviewed every morning. The goal of the DAX is to check if the hardware on a particular node has changed, and the equation below does this perfectly, by comparing todays value against yesterdays, and if there is a change, the output is 1, i.e, hardware swapped. If the node is a brand new node there will not be any information for yesterday so the output is 0.

Unfortunately there are days when the data feed can become corrupt and we may not receive it for a few days or sometimes a few weeks. The equation below only compares todays data with yesterdays data so if yesterdays information/data feed is missing the output is 0, even if hardware was swapped. Is there a way to change the equation to look for the most recently available data to compare todays data against?

 

Hardware Swap =
VAR __var1 = 'FieldReplaceableUnit_productData'[f_serialNumber]
VAR __var2 = CALCULATE(VALUES('FieldReplaceableUnit_productData'[f_serialNumber]), FILTER(ALL('FieldReplaceableUnit_productData'), 'FieldReplaceableUnit_productData'[Date created] = EARLIER('FieldReplaceableUnit_productData'[Date created]) - 1 && 'FieldReplaceableUnit_productData'[managedElementId/fieldReplaceableUnitId] = EARLIER('FieldReplaceableUnit_productData'[managedElementId/fieldReplaceableUnitId])))
RETURN
IF(ISBLANK(__var2), 0, IF(__var1 = __var2, 0, 1))
 
[Date created] is that date of the arrival of data feed for hardware information
1 ACCEPTED SOLUTION

Please check it this is the output that you're looking for:

_AAndrade_0-1712163386109.png


The Measure I'm using is this:

New Hardware Swap = 
VAR _SerialNumber = SELECTEDVALUE(FieldReplaceableUnit_productData[f_serialNumber])
VAR _MaxDate = 
    CALCULATE(
            MAX(FieldReplaceableUnit_productData[Date created]),
            FILTER(
                //ALL(FieldReplaceableUnit_productData),
                ALLEXCEPT(FieldReplaceableUnit_productData, FieldReplaceableUnit_productData[f_managedElementId], FieldReplaceableUnit_productData[f_fieldReplaceableUnitId]),
                FieldReplaceableUnit_productData[Date created] < MIN(FieldReplaceableUnit_productData[Date created])
            )
    )

VAR _Calculation = 
    CALCULATE(
        VALUES(FieldReplaceableUnit_productData[f_serialNumber]),
        FILTER(
            ALL(FieldReplaceableUnit_productData),
            FieldReplaceableUnit_productData[Date created] = _MaxDate && (FieldReplaceableUnit_productData[f_managedElementId] = SELECTEDVALUE(FieldReplaceableUnit_productData[f_managedElementId]) && FieldReplaceableUnit_productData[f_fieldReplaceableUnitId] = SELECTEDVALUE(FieldReplaceableUnit_productData[f_fieldReplaceableUnitId]))
            )
        )
VAR _Result = _Calculation

RETURN
    IF( ISBLANK(_Calculation), 0,
        IF(_SerialNumber = _Calculation,0,1)
    )




Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




View solution in original post

9 REPLIES 9
_AAndrade
Super User
Super User

@kinseld5 If my post solved your problem, please Mark as solution and give a Kudos, I Will appreciate that.

Thanks 





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




_AAndrade
Super User
Super User

Hi @kinseld5,

Please try this new measure and see if this solve your problem:

ardware Swap =
VAR __var1 = 'FieldReplaceableUnit_productData'[f_serialNumber]
VAR __mostRecentDate =
    CALCULATE(
        MAX('FieldReplaceableUnit_productData'[Date created]),
        ALLEXCEPT('FieldReplaceableUnit_productData', 'FieldReplaceableUnit_productData'[managedElementId/fieldReplaceableUnitId])
    )
VAR __var2 =
    CALCULATE(
        VALUES('FieldReplaceableUnit_productData'[f_serialNumber]),
        'FieldReplaceableUnit_productData'[Date created] = __mostRecentDate,
        'FieldReplaceableUnit_productData'[managedElementId/fieldReplaceableUnitId] = EARLIER('FieldReplaceableUnit_productData'[managedElementId/fieldReplaceableUnitId])
    )
RETURN
    IF(ISBLANK(__var2), 0, IF(__var1 = __var2, 0, 1))




Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Hi. Thanks for the feedback. I'm getting an error with equation provided, see below. Can you recommend a column equation as oppossed to a measure? The equation i mentioned previously was Column DAX

 

A single value for column 'f_serialNumber' in table 'FieldReplaceableUnit_productData' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result.

Can you share a sample data or a pbix file so I take a look?





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Sure, please see link below. You will notice that the hardware change on LK0191 was identified via the DAX equation sent on previously, but the one on DU0853 was not, because i'm missing data from the 29th Feb

 

https://drive.google.com/file/d/1CiqbhhnKhpuw4Nb75SmWbWo3DesHJud4/view?usp=drive_link

@kinseld5  you need to give me access





Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Access granted

Please check it this is the output that you're looking for:

_AAndrade_0-1712163386109.png


The Measure I'm using is this:

New Hardware Swap = 
VAR _SerialNumber = SELECTEDVALUE(FieldReplaceableUnit_productData[f_serialNumber])
VAR _MaxDate = 
    CALCULATE(
            MAX(FieldReplaceableUnit_productData[Date created]),
            FILTER(
                //ALL(FieldReplaceableUnit_productData),
                ALLEXCEPT(FieldReplaceableUnit_productData, FieldReplaceableUnit_productData[f_managedElementId], FieldReplaceableUnit_productData[f_fieldReplaceableUnitId]),
                FieldReplaceableUnit_productData[Date created] < MIN(FieldReplaceableUnit_productData[Date created])
            )
    )

VAR _Calculation = 
    CALCULATE(
        VALUES(FieldReplaceableUnit_productData[f_serialNumber]),
        FILTER(
            ALL(FieldReplaceableUnit_productData),
            FieldReplaceableUnit_productData[Date created] = _MaxDate && (FieldReplaceableUnit_productData[f_managedElementId] = SELECTEDVALUE(FieldReplaceableUnit_productData[f_managedElementId]) && FieldReplaceableUnit_productData[f_fieldReplaceableUnitId] = SELECTEDVALUE(FieldReplaceableUnit_productData[f_fieldReplaceableUnitId]))
            )
        )
VAR _Result = _Calculation

RETURN
    IF( ISBLANK(_Calculation), 0,
        IF(_SerialNumber = _Calculation,0,1)
    )




Did I answer your question? Mark my post as a solution! Kudos are welcome.

Proud to be a Super User!




Thank you. This has worked. Really appreciate the help

Helpful resources

Announcements
PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.