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
qmestu
Helper III
Helper III

Counting number of rows where there's one than more ocurrence

Hi,

 

I have the following data:

 

idcasestudyyear
1AS12023
2AS22023
3BS12023
4CS12022

5

CS22023

 

I'm trying to count the number of cases for each study where the case had another study in the same year. With my sample data, this would only be true for case A.

 

Thanks.

 

1 ACCEPTED SOLUTION
selimovd
Super User
Super User

Hey @qmestu ,

 

please check the attached file.

The following measure should work:

 

# Cases for additional studies same year = 
VAR _VirtualTable = 
ADDCOLUMNS (
    SUMMARIZE (
        myTable,
        myTable[study],
        myTable[case],
        myTable[year]
    ),
    "@CasesInSameYear",
    VAR _studyCurrentRow = myTable[study]
    VAR _caseCurrentRow = myTable[case]
    VAR _yearCurrentRow = myTable[year]
    RETURN
        CALCULATE (
            COUNTROWS( myTable ),
            myTable[case] = _caseCurrentRow
            && myTable[year] = _yearCurrentRow,
            ALL(myTable)
        ) - 1
)
RETURN
    SUMX( _VirtualTable, [@CasesInSameYear] )

 

 

In this case it will show a 1 or larger number if there is more than one match:

selimovd_0-1709158867042.png

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍

Best regards
Denis

Blog: WhatTheFact.bi
Follow me: twitter.com/DenSelimovic

 

View solution in original post

1 REPLY 1
selimovd
Super User
Super User

Hey @qmestu ,

 

please check the attached file.

The following measure should work:

 

# Cases for additional studies same year = 
VAR _VirtualTable = 
ADDCOLUMNS (
    SUMMARIZE (
        myTable,
        myTable[study],
        myTable[case],
        myTable[year]
    ),
    "@CasesInSameYear",
    VAR _studyCurrentRow = myTable[study]
    VAR _caseCurrentRow = myTable[case]
    VAR _yearCurrentRow = myTable[year]
    RETURN
        CALCULATE (
            COUNTROWS( myTable ),
            myTable[case] = _caseCurrentRow
            && myTable[year] = _yearCurrentRow,
            ALL(myTable)
        ) - 1
)
RETURN
    SUMX( _VirtualTable, [@CasesInSameYear] )

 

 

In this case it will show a 1 or larger number if there is more than one match:

selimovd_0-1709158867042.png

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍

Best regards
Denis

Blog: WhatTheFact.bi
Follow me: twitter.com/DenSelimovic

 

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.