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
scabral
Helper IV
Helper IV

flagging correct row in a group with date logic

Hi,

 

so this one is a little tricky but i have a table with the below columns:

 

ClaimIdLocationIdReserveDateAccuracyInd
1111991/1/20211
1111991/16/20211
1111994/1/20211
1111994/4/20211
1111776/1/20211
1111776/6/20210
1111777/1/20210
1111777/3/20210
2222333/3/20210
2222334/2/20210
2222335/1/20211
2222335/6/20210
2222338/1/20211
4444886/6/20210
4444887/4/20210
4444887/9/20211
5555768/1/20210
5555768/8/20210

 

For each ClaimId and LocationID group, i need to create a new calculated column (called GroupAccuracyInd) that will be either a 1 for the first row that became accurate (AccuracyInd = 1) after the max inaccurate row (AccuracyInd = 0).  So for the first group above (ClaimId 1111 LocationId 99) all rows are accurate so i will select the row with Reserve Date of 1/1/2021.  For the second group (ClaimId 1111 LocationId 77) I will need to flag the 6/1/2021 row since that was the first row that was accurate and no others.  For the third group (ClaimId 2222 LocationId 33) it becomes a little tricky.  The first row to become accurate is on 5/1/2021 but then it becomes inaccurate on 5/6/2021 and then accurate again on 8/1/2021.  I will need to flag the 8/1/2021 row since it's the first accurate row after the max inaccurate row for the group.  For the last group (ClaimId 5555 LocationId 76) there are no accurate rows so they will just default to 0.

 

so the final field should look like this:

 

ClaimIdLocationIdReserveDateAccuracyIndGroupAccuracyInd
1111991/1/202111
1111991/16/202110
1111994/1/202110
1111994/4/202110
1111776/1/202111
1111776/6/202100
1111777/1/202100
1111777/3/202100
2222333/3/202100
2222334/2/202100
2222335/1/202110
2222335/6/202100
2222338/1/202111
4444886/6/202100
4444887/4/202100
4444887/9/202111
5555768/1/202100
5555768/8/202100

 

Thanks

Scott

1 ACCEPTED SOLUTION

and this:

 

 

AccGroupFinal = 
VAR _claimId =
    MAX ( myTable[ClaimId] )
VAR _locationID =
    MAX ( myTable[LocationId] )
VAR _curDate =
    MAX ( myTable[ReserveDate] )

VAR _minDate =
    CALCULATE (
        MIN ( myTable[ReserveDate] ),
        FILTER (
            ALL ( myTable ),
            myTable[ClaimId] = _claimId
                && myTable[LocationId] = _locationID
                && myTable[AccuracyInd] = 1
        )
    )

Var _maxDateWithZero = CALCULATE (
        MAX(  myTable[ReserveDate] ),
        FILTER (
            ALL ( myTable ),
            myTable[ClaimId] = _claimId
                && myTable[LocationId] = _locationID
                && myTable[AccuracyInd] = 0))   //gets the max date with zero 

Var _choose= CALCULATE(MIN(myTable[ReserveDate]),FILTER(All(myTable),
            myTable[ClaimId] = _claimId
                && myTable[LocationId] = _locationID
                && myTable[AccuracyInd] = 1
                && myTable[ReserveDate]>_maxDateWithZero))


VAR _isMin =
    IF ( _minDate = _curDate, _minDate )//this displays blanks

Var _whichOne= IF(_maxDateWithZero>_choose,_minDate,_choose)
RETURN
  
 // if(_whichOne = _curDate,_whichOne)

 IF(_whichOne=_curDate,1,0)

 

 

Which gives us this:
Capturefin.PNG

 

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

 







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
Nathaniel_C
Super User
Super User

Hi @scabral you are welcome!
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Nathaniel_C
Super User
Super User

Hi @scabral , Try this:

AccGroup =
VAR _claimId =
    MAX ( myTable[ClaimId] )
VAR _locationID =
    MAX ( myTable[LocationId] )
VAR _curDate =
    MAX ( myTable[ReserveDate] )
VAR _minDate =
    CALCULATE (
        MIN ( myTable[ReserveDate] ),
        FILTER (
            ALL ( myTable ),
            myTable[ClaimId] = _claimId
                && myTable[LocationId] = _locationID
                && myTable[AccuracyInd] = 1
        )
    )
VAR _isMin =
    IF ( _minDate = _curDate, _minDate )
RETURN
    _isMin



Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




and this:

 

 

AccGroupFinal = 
VAR _claimId =
    MAX ( myTable[ClaimId] )
VAR _locationID =
    MAX ( myTable[LocationId] )
VAR _curDate =
    MAX ( myTable[ReserveDate] )

VAR _minDate =
    CALCULATE (
        MIN ( myTable[ReserveDate] ),
        FILTER (
            ALL ( myTable ),
            myTable[ClaimId] = _claimId
                && myTable[LocationId] = _locationID
                && myTable[AccuracyInd] = 1
        )
    )

Var _maxDateWithZero = CALCULATE (
        MAX(  myTable[ReserveDate] ),
        FILTER (
            ALL ( myTable ),
            myTable[ClaimId] = _claimId
                && myTable[LocationId] = _locationID
                && myTable[AccuracyInd] = 0))   //gets the max date with zero 

Var _choose= CALCULATE(MIN(myTable[ReserveDate]),FILTER(All(myTable),
            myTable[ClaimId] = _claimId
                && myTable[LocationId] = _locationID
                && myTable[AccuracyInd] = 1
                && myTable[ReserveDate]>_maxDateWithZero))


VAR _isMin =
    IF ( _minDate = _curDate, _minDate )//this displays blanks

Var _whichOne= IF(_maxDateWithZero>_choose,_minDate,_choose)
RETURN
  
 // if(_whichOne = _curDate,_whichOne)

 IF(_whichOne=_curDate,1,0)

 

 

Which gives us this:
Capturefin.PNG

 

 


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel

 







Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi Nathaniel_C,

 

this seems to work well.  I only had to remove the MAX from teh initial variables and then it seems to be correct.

 

Thanks for your help!

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.

Top Solution Authors