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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
PNL
New Member

How to count records for different range including negative ?

Hi Community,

 

My Power Bi data model has 4 tables :

 

sample data.jpg
Feedback Records Master (Records all feedbacks with location, channel and rating details)

Channel Master (Stores different channels available at different locations. Not all channels are available at all locations)

Rating Master (Defines rating range and interpretation)

Location Master (Stores all available locations)

 

I need to write a measure or 2 separate measures to count no of countries with Poor feedback and Good feedback

Kindly help.

 

Thanks,

PNL

1 ACCEPTED SOLUTION
daXtreme
Solution Sage
Solution Sage

@PNL 

 

Here's something you could adjust to your needs...

[# Good Feedback Countries] =
// If you want a measure for "Poor",
// change the FeedbackCategory variable
// and it'll work.
var FeedbackCategory = "Good"
var FeedbackMin = 
    calculate(
        selectedvalue( 'Rating Master'[Min] ),
        'Rating Master'[Feedback] = FeedbackCategory,
        removefilters( 'Rating Master' )
    )
var FeedbackMax = 
    calculate(
        selectedvalue( 'Rating Master'[Max] ),
        'Rating Master'[Feedback] = FeedbackCategory,
        removefilters( 'Rating Master' )
    )
var Output = 
    caclulate(
        distinctcount( 'Feedback Record Master'[Location] ),
        // If you want to be able to also slice by Rating
        // (this is not recommended), you should wrap the
        // two conditions in KEEPFILTERS, like:
        // keepfilters( 'Feedback Record Master'[Rating] >= FeedbackMin )
        // It's needed if you want to work within the current
        // filter context without overwriting it. If you hide
        // the Rating column (you should always hide your fact tables)
        // then you don't need this directive.
        'Feedback Record Master'[Rating] >= FeedbackMin,
        // adjust the boundaries accordingly in both condtions.
        'Feedback Record Master'[Rating] < FeedbackMax
    )
return
    Output

View solution in original post

2 REPLIES 2
daXtreme
Solution Sage
Solution Sage

@PNL 

 

Here's something you could adjust to your needs...

[# Good Feedback Countries] =
// If you want a measure for "Poor",
// change the FeedbackCategory variable
// and it'll work.
var FeedbackCategory = "Good"
var FeedbackMin = 
    calculate(
        selectedvalue( 'Rating Master'[Min] ),
        'Rating Master'[Feedback] = FeedbackCategory,
        removefilters( 'Rating Master' )
    )
var FeedbackMax = 
    calculate(
        selectedvalue( 'Rating Master'[Max] ),
        'Rating Master'[Feedback] = FeedbackCategory,
        removefilters( 'Rating Master' )
    )
var Output = 
    caclulate(
        distinctcount( 'Feedback Record Master'[Location] ),
        // If you want to be able to also slice by Rating
        // (this is not recommended), you should wrap the
        // two conditions in KEEPFILTERS, like:
        // keepfilters( 'Feedback Record Master'[Rating] >= FeedbackMin )
        // It's needed if you want to work within the current
        // filter context without overwriting it. If you hide
        // the Rating column (you should always hide your fact tables)
        // then you don't need this directive.
        'Feedback Record Master'[Rating] >= FeedbackMin,
        // adjust the boundaries accordingly in both condtions.
        'Feedback Record Master'[Rating] < FeedbackMax
    )
return
    Output
daXtreme
Solution Sage
Solution Sage

@PNL 

 

What would you want to see if you slice by country only and one country has a good feedback for one channel and a bad one for another? Please remember that measures should always work correctly for any slices in dimensions. Your definition of what you want to do is not clear enough for all possible slices. Please make more clear. For instance, a [Good Feedback] measure would then return 1 or 0 or... what? Maybe blank to inform somebody that there are countries with both types of feedback? Or maybe some other code?

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.