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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
horaciorek
New Member

Count data based on slicer parameters

Please look at this dashboard just created to illustrate my problem:

horaciorek_0-1692262333695.png

First slicer represents the number of years (times) where data exists for an indicator series.

Second slicer represent the year to count from.

For Albania, as i show in the table, the series count should be 3. For Armenia should be 2.

 

The dashboard is using this data sample:

CountryYearIndicatorSeries
Albania20151.1.1ind1
Albania20101.1.1ind1
Albania20161.1.1ind1
Albania20181.1.1ind2
Albania20111.1.1ind2
Albania20191.1.1ind2
Albania20151.1.1ind2
Albania20102.1.1ind3
Albania20162.1.1ind3
Albania20182.1.1ind4
Albania20112.1.1ind4
Albania20192.1.1ind4
Armenia20111.1.1ind1
Armenia20101.1.1ind1
Armenia20161.1.1ind1
Armenia20181.1.1ind2
Armenia20201.1.1ind2
Armenia20191.1.1ind2
Armenia20151.1.1ind2
Armenia20162.1.1ind3
Armenia20162.1.1ind3
Armenia20182.1.1ind4
Armenia20112.1.1ind4
Armenia20202.1.1ind4
Armenia20102.1.1ind4

 

This is my measure:

IndicatorSeriesCount = 
VAR FilteredData =
    FILTER(
        Data,
        Data[Year] >= [Year Value]
    )
VAR IndicatorSeriesCounts =
    SUMMARIZE(
        FilteredData,
        Data[Indicator],
        Data[Series],
        "YearCount", COUNTROWS(FilteredData)
    )
VAR IndicatorSeriesWithMultipleYearsCount =
    COUNTROWS(
        FILTER(
            IndicatorSeriesCounts,
            [YearCount] > [Years Value]
        )
    )
RETURN   IndicatorSeriesWithMultipleYearsCount

I think the problem is that i need to include a distinctcount somewhere, but i am not sure where.

 

Download the Pbix file here

I'd appreciate any help. Thanks!

1 ACCEPTED SOLUTION
horaciorek
New Member

This measure did the trick:

Filtered = 

VAR FilteredData =

    FILTER(

        Data,

        Data[Year] >= [Year Value]

    )

VAR SummaryTable =

    SUMMARIZE(

        FilteredData,

        Data[Country],

        Data[Indicator],

        Data[Series],

        "YearCount", CALCULATE(DISTINCTCOUNTNOBLANK(Data[Year]))

    )

VAR IndicatorSeriesWithMultipleYearsCount =

    COUNTROWS( FILTER(SummaryTable, [YearCount] >= Years[Years Value]))

RETURN

    IndicatorSeriesWithMultipleYearsCount

View solution in original post

3 REPLIES 3
horaciorek
New Member

This measure did the trick:

Filtered = 

VAR FilteredData =

    FILTER(

        Data,

        Data[Year] >= [Year Value]

    )

VAR SummaryTable =

    SUMMARIZE(

        FilteredData,

        Data[Country],

        Data[Indicator],

        Data[Series],

        "YearCount", CALCULATE(DISTINCTCOUNTNOBLANK(Data[Year]))

    )

VAR IndicatorSeriesWithMultipleYearsCount =

    COUNTROWS( FILTER(SummaryTable, [YearCount] >= Years[Years Value]))

RETURN

    IndicatorSeriesWithMultipleYearsCount
tamerj1
Super User
Super User

Hi @horaciorek 
Please try

IndicatorSeriesCount = 
VAR FilteredData =
    FILTER(
        Data,
        Data[Year] >= [Year Value]
    )
VAR IndicatorSeriesCounts =
    SUMMARIZE(
        FilteredData,
        Data[Indicator],
        Data[Series],
        "@YearCount", COUNTROWS(Data)
    )
VAR IndicatorSeriesWithMultipleYearsCount =
    COUNTROWS(
        FILTER(
            IndicatorSeriesCounts,
            [@YearCount] >= [Years Value]
        )
    )
RETURN
    IndicatorSeriesWithMultipleYearsCount

Thanks for your effort, but it doesn't seem to do the trick. With your measure, using the values I have in the image, it gives me 3 for both countries, when it should be 2 for Armenia...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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