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
Pbiuserr
Post Prodigy
Post Prodigy

How to calculate repeated ID and dates only once?

Hello,

My dataset looks like that. I'd need to calculate count of ID with earliest date excatly once and only for each ID.Status needs to be "B"

 

Pbiuserr_0-1657626833350.png

 

1 ACCEPTED SOLUTION

Ok, I've tested this out. Since you have several rows with the same ID, CrashDate and Status, unless you add an index to differentiate these rows (or there's another field which renders each row unique), PBI will summarize these rows into a single row.

 

1) So, to keep your structure and show all the rows, I have added an index column to render each row unique. As I say, if there is a field in the data which makes each row unique, you can use that field instead of the Index field I've used in the measure.

I have worked on this sample dataset (including the Index column)
set.pngThe measure:

 

Min date per ID single row =
VAR _MinDateID =
    CALCULATE (
        MIN ( FTable[CrashDate] ),
        FILTER ( ALLEXCEPT ( FTable, FTable[ID] ), FTable[Status] = "B" )
    )
VAR _SelID =
    MAX ( FTable[ID] )
VAR _MinRow =
    CALCULATE (
        MIN ( FTable[Index] ),
        FILTER ( ALL ( FTable ), FTable[CrashDate] = _MinDateID && FTable[ID] = _SelID )
    ) // IF you have a field which renders each row unique, use the field (you don't then need the index column)
VAR _Summary =
    SUMMARIZE (
        FILTER ( FTable, FTable[Index] = _MinRow && FTable[CrashDate] = _MinDateID ),
        FTable[ID],
        FTable[CrashDate]
    ) // Again, if you have the unique field, use it instead of the FTable[Index] field
RETURN
    IF ( COUNTROWS ( _Summary ) = 1, _MinDateID )

 

Which gets you this:

resukt 1.png2) If you don't need to show all the rows, and the summary suffices (you don't need the index column), you can use this measure:

 

Min date by Id for "B" Status =
VAR _MinDateID =
    CALCULATE (
        MIN ( 'FTable'[CrashDate] ),
        FILTER ( ALLEXCEPT ( 'FTable', 'FTable'[ID] ), 'FTable'[Status] = "B" )
    )
VAR _Summary =
    SUMMARIZE (
        FILTER ( FTable, FTable[CrashDate] = _MinDateID ),
        FTable[CrashDate],
        [ID]
    )
RETURN
    IF ( COUNTROWS ( _Summary ) = 1, _MinDateID )

 

To get:

Res2.pngI've attached the sample PBIS file

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

6 REPLIES 6
v-easonf-msft
Community Support
Community Support

Hi, @Pbiuserr 

Please try formula like:

Count =
CALCULATE (
    DISTINCTCOUNT ( Table[ID] ),
    FILTER ( ALLEXCEPT ( Table, Table[Date].[Month] ), Table[Status] = "B" )
)

If it doesn't work, please explain further your expected results

 

Best Regards,
Community Support Team _ Eason

PaulDBrown
Community Champion
Community Champion

If you need the earliest date by IP and Status, try:

Min date = CALCULATE (MIN(Table[Date]), ALLEXCEPT(Table, Table[IP], Table[Status]))





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






PaulDBrown
Community Champion
Community Champion

Try:

Min date = CALCULATE (MIN(Table[Date]), FILTER(ALLEXCEPT(Table, Table[IP]), Table [Status] = "B"))





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Hi,

It gives me only earliest date from entire dataset. I'd like to count earliest date per ID with that status. Could you help me?

Ok, I've tested this out. Since you have several rows with the same ID, CrashDate and Status, unless you add an index to differentiate these rows (or there's another field which renders each row unique), PBI will summarize these rows into a single row.

 

1) So, to keep your structure and show all the rows, I have added an index column to render each row unique. As I say, if there is a field in the data which makes each row unique, you can use that field instead of the Index field I've used in the measure.

I have worked on this sample dataset (including the Index column)
set.pngThe measure:

 

Min date per ID single row =
VAR _MinDateID =
    CALCULATE (
        MIN ( FTable[CrashDate] ),
        FILTER ( ALLEXCEPT ( FTable, FTable[ID] ), FTable[Status] = "B" )
    )
VAR _SelID =
    MAX ( FTable[ID] )
VAR _MinRow =
    CALCULATE (
        MIN ( FTable[Index] ),
        FILTER ( ALL ( FTable ), FTable[CrashDate] = _MinDateID && FTable[ID] = _SelID )
    ) // IF you have a field which renders each row unique, use the field (you don't then need the index column)
VAR _Summary =
    SUMMARIZE (
        FILTER ( FTable, FTable[Index] = _MinRow && FTable[CrashDate] = _MinDateID ),
        FTable[ID],
        FTable[CrashDate]
    ) // Again, if you have the unique field, use it instead of the FTable[Index] field
RETURN
    IF ( COUNTROWS ( _Summary ) = 1, _MinDateID )

 

Which gets you this:

resukt 1.png2) If you don't need to show all the rows, and the summary suffices (you don't need the index column), you can use this measure:

 

Min date by Id for "B" Status =
VAR _MinDateID =
    CALCULATE (
        MIN ( 'FTable'[CrashDate] ),
        FILTER ( ALLEXCEPT ( 'FTable', 'FTable'[ID] ), 'FTable'[Status] = "B" )
    )
VAR _Summary =
    SUMMARIZE (
        FILTER ( FTable, FTable[CrashDate] = _MinDateID ),
        FTable[CrashDate],
        [ID]
    )
RETURN
    IF ( COUNTROWS ( _Summary ) = 1, _MinDateID )

 

To get:

Res2.pngI've attached the sample PBIS file

 

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Thanks! Very insightful and helpful. Turned out that your first measure along with MIN on dates is fine, but I guess you achieved the same result. Thank you very much!

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.