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

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.

Reply
Georgia_H
Helper I
Helper I

How to flag out whether the record exists in previous period

Hello, i need some help. I want to achieve 2 things:

1. A calc column/measure to flag out new QIDs as 1 when compare against previous period (in my case previous week) for different Business Unit. 

2.  A calc column/measure to flag out existing QIDs as 0 when compare against previous period (in my case previous week) for different Business Unit. 

So far, I cannot get the results i wanted. See snipet in the highlighted blue box.

E.g: QID 38169 is a new QID detected in Week 25 for this particular LBU but is flagged out as 0 instead of 1. I also attached my formula. Please enlighten me what is amiss here. Thank you.Sample code.PNG

Sample issue.png

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @Georgia_H ,

 

According to my understanding, you want to set a flag based on QID that it will identify whether the QID is a new one or an existed one.

If so, please use the following formula to create a measure:

Flag =
VAR _t =
    SUMMARIZE (
        FILTER (
            ALL ( 'Table' ),
            'Table'[LBU] = MAX ( 'Table'[LBU] )
                && 'Table'[Last Detected] < MAX ( 'Table'[Last Detected] )
        ),
        [QID]
    )
VAR _first =
    CALCULATE (
        FIRSTNONBLANK ( 'Table'[Last Detected], TRUE () ),
        ALLEXCEPT ( 'Table', 'Table'[LBU] )
    )
RETURN
    IF (
        MAX ( 'Table'[Last Detected] ) = _first,
        0,
        IF ( MAX ( 'Table'[QID] ) IN _t, 0, 1 )
    )

The final output is shown below:

flag for new or existed.PNG


Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Ashish_Mathur
Super User
Super User

Hi,

Could you share the download link of your PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-eqin-msft
Community Support
Community Support

Hi @Georgia_H ,

 

According to my understanding, you want to set a flag based on QID that it will identify whether the QID is a new one or an existed one.

If so, please use the following formula to create a measure:

Flag =
VAR _t =
    SUMMARIZE (
        FILTER (
            ALL ( 'Table' ),
            'Table'[LBU] = MAX ( 'Table'[LBU] )
                && 'Table'[Last Detected] < MAX ( 'Table'[Last Detected] )
        ),
        [QID]
    )
VAR _first =
    CALCULATE (
        FIRSTNONBLANK ( 'Table'[Last Detected], TRUE () ),
        ALLEXCEPT ( 'Table', 'Table'[LBU] )
    )
RETURN
    IF (
        MAX ( 'Table'[Last Detected] ) = _first,
        0,
        IF ( MAX ( 'Table'[QID] ) IN _t, 0, 1 )
    )

The final output is shown below:

flag for new or existed.PNG


Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

vanessafvg
Super User
Super User

it looks like your lastdetected column is a datetime?  if you comparing dates they both have to be dates ad not datetime.  

 

have you gone through your code variables and checked that each variable or condition you use is returning the values back you expect?

 

Also in terms  of your or statement, have you tested the values being returned?





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.