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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
PatrickNahayo
Frequent Visitor

Show actual counts and 0 values in calculated table column (to identify the gap in products)

Hi

i have the following table where we have the possibilities for the same ID to be assigned a grade multiple times in the dataset. 

idgrade (A,B,C,D)count
1A1
1B2
1C2
2C1
2D1
2B1

However looking at this example, i need to show that there are some gaps, so that we can introduce product recommendations.

I need to create a calculated table or a column that will show me the nulls or 0 values as well in each category where we don't have a product count for example 1D has nothing, and 2A.

id+gradecount (with 0 or nulls)
1A1
1B2
1C2
1D0
2A0
2B1
2C1
2D1

I have tried the following measures but is not working in a calculated column:

    CountID =
    var vCountGrades =
        CALCULATE(
            COUNTROWS('Products'),
            FILTER(
                'Products',
                'Products'[ID] = EARLIER('Products'[ID]) &&
                'Products'[grade]= EARLIER('Products'[grade])
            )
        )
    RETURN
        IF(ISBLANK(vCountGrades ), 0, vCountGrades )
2 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

@PatrickNahayo Try this as a new calculated table:

Table 2 = 
ADDCOLUMNS(
    GENERATE(
        DISTINCT('Table'[id]),
        DISTINCT('Table'[grade])
    ),
    "count", 
        VAR __id = [id]
        VAR __grade = [grade]
        VAR __result = MAXX( FILTER('Table', [id] = __id && [grade] = __grade ), [count] ) + 0
    RETURN
        __result
)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Anonymous
Not applicable

Hi @PatrickNahayo 

 

Your solution is great, @Greg_Deckler . Here I have another idea in mind, and I would like to share it for reference.

 

@PatrickNahayo , you can create a calculated table as follows.

 

 

 

CalculatedTable = 
VAR _IDList = DISTINCT('Table'[id])
VAR _GradeList = DISTINCT('Table'[grade])
VAR _AllCombinations = CROSSJOIN(_IDList, _GradeList)
RETURN
ADDCOLUMNS(
    _AllCombinations,
    "count", COALESCE([countMeasure], 0)
)

 

 

The reason I created [countMeasure] is that I don't know how your count expression is calculated, I created that formula just to get an expression because the COALESCE formula requires an expression as its argument. You can replace it with your [count] expression.

 

Output:

vxuxinyimsft_0-1718692172004.png

 

For more details, you can read related document link:

COALESCE function (DAX) - DAX | Microsoft Learn

 

Best Regards,
Yulia Xu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
PatrickNahayo
Frequent Visitor

Thanks very much for your inputs and solutions that have worked great @Greg_Deckler @Anonymous 
However i need to solve an additional analytics task on top of this to recommend which products is the best, i have tried with multiple IFs and SWITCH statements but with no satisfying results.
Basically i need to compare for each product which highest grade has the highest number in each category and mark that with an X so that i can compare with what doesn't have.

  A=high, D=lowA=high, C=low  
idcategorygrade 1grade 2qty grade 1qty grade 2recommend
11AC13 
21BA24x
31CB45 
41DA02 
52AB23 
62AA22x
72CB13 
82DC12 

Thanks very much again for your assistance on this matter

Anonymous
Not applicable

Hi @PatrickNahayo 

 

Your solution is great, @Greg_Deckler . Here I have another idea in mind, and I would like to share it for reference.

 

@PatrickNahayo , you can create a calculated table as follows.

 

 

 

CalculatedTable = 
VAR _IDList = DISTINCT('Table'[id])
VAR _GradeList = DISTINCT('Table'[grade])
VAR _AllCombinations = CROSSJOIN(_IDList, _GradeList)
RETURN
ADDCOLUMNS(
    _AllCombinations,
    "count", COALESCE([countMeasure], 0)
)

 

 

The reason I created [countMeasure] is that I don't know how your count expression is calculated, I created that formula just to get an expression because the COALESCE formula requires an expression as its argument. You can replace it with your [count] expression.

 

Output:

vxuxinyimsft_0-1718692172004.png

 

For more details, you can read related document link:

COALESCE function (DAX) - DAX | Microsoft Learn

 

Best Regards,
Yulia Xu

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Community Champion
Community Champion

@PatrickNahayo Try this as a new calculated table:

Table 2 = 
ADDCOLUMNS(
    GENERATE(
        DISTINCT('Table'[id]),
        DISTINCT('Table'[grade])
    ),
    "count", 
        VAR __id = [id]
        VAR __grade = [grade]
        VAR __result = MAXX( FILTER('Table', [id] = __id && [grade] = __grade ), [count] ) + 0
    RETURN
        __result
)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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.