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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

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
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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